• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate join into single object

 
James Daniel
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to do a select that joins two tables by id (j.id = m.jobId) and get a single value (j.name) that will be single object. When I make a join call, I get an array of objects. I need to pass a single type of object to a DisplayTag page. What is the best way to do this?

Jim
 
Anantha Sharma
Ranch Hand
Posts: 43
Android Hibernate jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if you are using Criteria you can use projections to select only one field from the query,



if you are using HQL you can say

 
James Daniel
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anantha, thanks so much for your reply. I have been unable to set that value in the object that I need to pass on to a page. In the example below, I have two objects. The join is at id/jobId. jobName is the value I want to set though it isn't an actual column in the database. I just need to display the job name with the module information. When I do a join in Hibernate, I get an array of objects whereas I need only of type Module but with the value "jobName" set from the join to Job. Is that possible? I may be missing something in your example but since I need values from two tables but only want to create a list of objects of one type, how do get just the single value from Job without adding objects of type Job to the list?

Example:

JOB
id
name

MODULE
id
name
jobId
jobName
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic