my dog learned polymorphism*
The moose likes Object Relational Mapping and the fly likes How does Hibernate handle a nullable foreign key in a query? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "How does Hibernate handle a nullable foreign key in a query?" Watch "How does Hibernate handle a nullable foreign key in a query?" New topic
Author

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

Mike London
Ranch Hand

Joined: Jul 12, 2002
Posts: 1034
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

Joined: May 13, 2002
Posts: 180
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

Joined: Jul 12, 2002
Posts: 1034
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
 
subject: How does Hibernate handle a nullable foreign key in a query?
 
Similar Threads
SQL statements
Hibernate @DiscriminatorColumn
Criteria Issue
JOIN syntax for HQL . Need help!
composite-id, one-to-one, formula, and an outer join