Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Hibernate join into single object

 
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
 
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
 
All that thinking. Doesn't it hurt? What do you think about this tiny ad?
Two software engineers solve most of the world's problems in one K&R sized book
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic