Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

hibernate get parent based on children

 
adsf da
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have parent.. which takes list of children

the mappings are correct.

how can i get parent.. based on sthg of children

select * from parent where parent_id in (select parent_id from children)


gethibernatetemplate().find(" from parent where parent_id in (select parent_id from children)
");

the above doesnt work.. anyone got solution?
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello nameless, why do you think your mappings are correct? Why don't you post them? How can WE know how YOU name YOUR fields?
 
adsf da
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try "from Parent p where p.child is not empty". This should bring you all Parents that have children.

BTW If you use HQL you have to use the properties of your java files, not the db columns.
 
adsf da
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i want is this


select * from parent where parent_id in (select parent_id from children where name = 'krikor herlopian')


gethibernatetemplate().find(" from parent where parent_id in (select parent_id from children where name = 'krikor herlopian')
");

the above doesnt work.. ..
 
Christian Dillinger
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"from Parent p where 'krikor herlopian' in (select c.name from p.child c)"
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic