File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes hibernate get parent based on children Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate get parent based on children" Watch "hibernate get parent based on children" New topic
Author

hibernate get parent based on children

adsf da
Greenhorn

Joined: Feb 24, 2010
Posts: 3
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

Joined: Jul 20, 2009
Posts: 188
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

Joined: Feb 24, 2010
Posts: 3
Christian Dillinger
Ranch Hand

Joined: Jul 20, 2009
Posts: 188
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

Joined: Feb 24, 2010
Posts: 3
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

Joined: Jul 20, 2009
Posts: 188
"from Parent p where 'krikor herlopian' in (select c.name from p.child c)"
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate get parent based on children