aspose file tools*
The moose likes Object Relational Mapping and the fly likes Hibernate querying two tables using join Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate querying two tables using join" Watch "Hibernate querying two tables using join" New topic
Author

Hibernate querying two tables using join

coder.shiv coder
Greenhorn

Joined: Jul 26, 2013
Posts: 1
Hey guys I`m new in hibernate and in posting issues here too.

I used JDBC till now and used to code like

select * from apple as a join banana as b on b.color=a.color;

apple.setAppleId(resultset.getLong("a.apple_id"));
apple.setColor(resultset.getString("a.color"));
banana.setBananaId(resultset.getLong("b.banana_id"));
banana.setColor(resultset.getLong("b.color"));

How to do this in hibernate using annotation mappings?

Please help.

vijay jacob
Ranch Hand

Joined: Jul 02, 2013
Posts: 57
Annotate the basic hibernate class. any simple hibernate example would do.

Then either you can use hql to do your sql stuff.

I believe apple and banana has no real association (mean to say one2many or many2one o)?

So i believe in that case hql is way out.

 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate querying two tables using join