Win a copy of Spring Boot in Practice this week in the Spring forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Liutauras Vilda
  • Henry Wong
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Mikalai Zaikin
  • Himai Minh

Hibernate join into single object

 
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 43
Android Hibernate jQuery
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
reply
    Bookmark Topic Watch Topic
  • New Topic