I have the same problem. I am performance tuning my application and it is taking a big hit because of this.
My definition of the problem is this: I am fetching child objects which may or may not have a parent. The child's foreign key points to a non-primary key on the parent. This is not reflected by a foreign key constraint in the database (hence it allows child to have no parent).
If the child object has the foreign key 0 instead of null, which is the protocol in this database, then the parent which doesn't exist is not (& cannot) be instantiated, no problem, but then after processing the resultset, Hibernate fires off another query to fetch the parent that it could not find data for in the first query.
Obviously this is not an ideal mapping, since the database doesn't contain any relationships to enforce it, but this is obviously unexpected and inappropriate behaviour.
However this new app is a call-centre sitting on top of a very 'established' database, and I don't have the choice.
I have entered it in Jira as a minor bug.
http://opensource.atlassian.com/projects/hibernate/browse/HHH-2073
Feel free to vote for the bug. With a bit of luck it might not be such a big issue to change in the source - I haven't got as far as looking into Hib src changes yet.
Here's the mappings:
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="test.parent.basic.BasicParent"
entity-name="test.parent.Parent" table="PARENT">
<id name="id" column="PARENT_ID" access="field">
<generator class="native" />
</id>
<property name="description" column="DESCRIPTION" not-null="true"
access="field" />
<property name="otherId" column="OTHER_ID" not-null="false" access="field"/>
</class>
<class name="test.child.basic.BasicChild"
entity-name="test.child.Child" table="CHILD">
<id name="id" column="CHILD_ID" access="field">
<generator class="native" />
</id>
<property name="description" column="DESCRIPTION" not-null="true"
access="field" />
<many-to-one name="parent" property-ref="otherId" access="field"
column="UNIQUE_PARENT" fetch="join" not-found="ignore" lazy="false"
outer-join="true" />
</class>
</hibernate-mapping>