Win a copy of Java 9 Revealed this week in the Features new in Java 9 forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Hibernate join returning a list of objects from one table in the join  RSS feed

Chris Spierings
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've done a couple of projects with hibernate but I can't seem to get this sort of thing to work. I have to classes IncentiveObj and IncentiveOwnerObj I want to return an IncentiveObj for those rows on the IncentiveOwnerObj (related table actually) where the other parts of the where clause are specified that is the first_Name and last_Name match the string's passed. Both share a field called incentive_id which I am joining on.

I have tried different things the last being to create a contructor on the object I want which accepts a paramter but then I get a list of objects with only that field filled. If I add the other columms to the constructor it doesn't work.

Here is the select string I'm passing to the query currently.

private String INCENTIVE_BY_OWNER = "SELECT new" + "from IncentiveObj i," + " IncentiveOwnerObj io " +
"where i.incentive_Id = io.incentive_Id " + " and io.first_Name = 'Kristie'" + " and io.last_Name = 'Sands'";

Can this sort of thing be done without reading the tables independent of each other and iterating through one of the resulting lists and reading the other table?


  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!