File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How does Hibernate handle a nullable foreign key in a query?

 
Mike London
Ranch Hand
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you have, say, a CUSTOMER table with a ORDERS table where the customer foreign key in the ORDERS table can be null, will Hibernate automatically create a Left Outer Join so you can still see the customers without orders?

How do you configure how Hibernate does the joins (inner join, Left Outer Join, etc.)?

Thanks,

mike
 
Ogeh Ikem
Ranch Hand
Posts: 180
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
will Hibernate automatically create a Left Outer Join so you can still see the customers without orders?

When navigating an association, for example, customer.getOrders(), you can tell Hibernate to use an outer join when fetching Orders by specifying fetch="join" in the mapping file. Alternatively, you can use an equivalent fetch annotation.

You can also use hql or the criteria API to perform joins. If you need to use any database-specific features, you may use sql.
 
Mike London
Ranch Hand
Posts: 1158
1
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ogeh Ikem wrote:
will Hibernate automatically create a Left Outer Join so you can still see the customers without orders?

When navigating an association, for example, customer.getOrders(), you can tell Hibernate to use an outer join when fetching Orders by specifying fetch="join" in the mapping file. Alternatively, you can use an equivalent fetch annotation.

You can also use hql or the criteria API to perform joins. If you need to use any database-specific features, you may use sql.


Thanks very much.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic