I am mapping 2 classes with <many-to-one> or <one-to-one> with "property-ref" attribute
Code:
<class name="ClassA">
<id column="ID" ... >... </id>
<many-to-one name="b" column="ID" insert="false" update="false: class="ClassB" property-ref="a" />
</class>
<class name="ClassB">
<many-to-one name="a" column="A_ID" class="ClassA" />
</class>
Then using this HQL: what I expected is NHibernate can just send one query to the DB to fetch the data:
Code:
querystr = "from ClassA A inner join fetch A.b where a.ID = :paramID"
But NHibernate is acctually issuing 2 queries, the first one is what I expected, join fetched both ClassA and ClassB. But the 2nd one is a query to get ClassB AGAIN with condition "ClassB.A_ID = :p0"
If I get rid of "property-ref" in ClassA mapping, that means I need to add a column in ClassA's table named "B_ID", then the HQL can run with one query, but I don't like to change the table or create a View, it's a legacy database, and I am afraid View will be slow.
why this is happening, does Hibernate 3.x solved this already :?: