In Hibernate 3, I have a one-to-one relationship between two classes. I've followed the instructions from Java Persistance with Hibernate on pages 283 and 284. For one class, I have this:
<class name="FileCycleCurrent" table="FILE_CYCLE_CURRENT">
<composite-id class="FileCycleKey" mapped="true">
<key-property name="cycleDate" column="CYCLE_DATE"/>
<key-property name="fileId" column="FILE_ID"/>
</composite-id>
<property name="boxName" column="BOX_NAME"/>
<property name="updateCorpId" column="UPDATE_CORP_ID"/>
<many-to-one name="feedFile" class="FeedFile" column="FILE_ID" insert="false" update="false" unique="true"/>
</class>
In the other class, I have the following:
<class name="FeedFile" table="FEED_FILE_VW">
<id name="fileId" column="FILE_ID"/>
<property name="fileName" column="FILE_NAME"/>
<property name="expectedBusDate" column="EXPECTED_BUS_DATE" update="false" insert="false"/>
<one-to-one name="fileCycleCurrent" class="FileCycleCurrent" property-ref="feedFile"/>
</class>
I do a query again FileCycleCurrent and the jsp references fields in the FeedFile table. This all works correctly when displaying the page.
However, when I display the sql, I'm getting 3 sql statements when I only expect 2:
1) The query against FileCycleCurrent which is what the hql goes against.
2) The query against FeedFile which is run after the jsp page realizes it needs data from this table as well since lazy loading is being used.
3) A third query I don't expect is another query against FileCycleCurrent without the values in the HQL. It's like the FeedFile is getting this information again (Filecyclecurrent to feedfile and back to filecyclecurrent)
Why would the third query be running? It's pulling the same data as query 1 which is inefficient. Query 1 runs and if no data is pulled, queries 2 or 3 don't run. Since it's lazy loading I would expect query 2 not to run, but it shows that filecyclecurrent is doing something cyclical here.
I thought having the property-ref there says that it's inverse so it shouldn't do this.
Any idea why I'm getting this third query?
Thanks.
|