Hibernate version: 3.2.4
Name and version of the database you are using: Oracle 10gR2
I have the following mappings (actual names changed):
Parent table:
Code:
<hibernate-mapping>
<class name="ClassParent" table="ParentT">
<composite-id name="id" class="...">
<key-property name="parentSeqNbr" type="big_decimal">
<column name="PARENT_SEQ_NBR" precision="10" scale="0" />
</key-property>
<key-property name="parentSiteCd" type="string">
<column name="PARENT_SITE_CD" length="11" />
</key-property>
</composite-id>
</class>
</hibernate-mapping>
Child table:
Code:
<hibernate-mapping>
<class name="ClassChild" table="ChildT">
<composite-id name="id" class="...">
<key-property name="childSeqNbr" type="big_decimal">
<column name="CHILD_SEQ_NBR" precision="10" scale="0" />
</key-property>
<key-property name="childSiteCd" type="string">
<column name="CHILD_SITE_CD" length="11" />
</key-property>
</composite-id>
<many-to-one name="parentRecord" not-found="ignore" class="ClassParent" fetch="select" lazy="proxy" >
<column name="PARENT_SEQ_NBR" precision="10" scale="0" />
<column name="PARENT_SITE_CD" length="11" />
</many-to-one>
</class>
</hibernate-mapping>
When I query the child table by running some hql, if it has a parent record associated to it, the record gets automatically loaded - no proxy created. After doing some digging, it seems to me that this is caused by the code in SessionImpl.internalLoad method:
Code:
public Object internalLoad(String entityName, Serializable id, boolean eager, boolean nullable) throws HibernateException {
// todo : remove
LoadEventListener.LoadType type = nullable ?
LoadEventListener.INTERNAL_LOAD_NULLABLE :
eager ? LoadEventListener.INTERNAL_LOAD_EAGER : LoadEventListener.INTERNAL_LOAD_LAZY;
LoadEvent event = new LoadEvent(id, entityName, true, this);
fireLoad(event, type);
if ( !nullable ) {
UnresolvableObjectException.throwIfNull( event.getResult(), id, entityName );
}
return event.getResult();
}
It looks like if nullable is true, then type is set to LoadEventListener.INTERNAL_LOAD_NULLABLE, which calls setAllowProxyCreation(false). This prevents DefaultLoadEventListener from creating a proxy for this entity. Also, there's a "todo:remove" comment in this method, which makes me think this is a known issue - is it? I couldn't find any resolution on the web.
I do have proxying enabled in general in the app. It works for not-nullable relationships, and I can actually see the CGLIB proxy class for the Parent class in the heap dump from this app (even though there are no instances of the proxy class - I believe the class is generated anyway on Hibernate initialization).
I appreciate any insight or help with this issue.
Thanks,
Andrey