Quote:
try constrained="true", lazy="no proxy"
I was hoping to not have to implement any byte-code instrumentation, which the lazy="no-proxy" requires.
In order to attempt to solve my explicit problem, allow me to explain my issue in more detail. I have an object called PropertyVO that represents a Hotel property, and it only contains the most basic information about a property. This PropertyVO contains a PropertyInfoVO . The following is the code and mapping file for the PropertyVO:
Code:
public class PropertyVO {
private Long propertyId;
private PropertyInfoVO propertyInfo;
private String marshaCode;
public PropertyVO() {
}
public Long getPropertyId() {
return this.propertyId;
}
public void setPropertyId(Long propertyId) {
this.propertyId = propertyId;
}
public PropertyInfoVO getPropertyInfo() {
return propertyInfo;
}
public void setPropertyInfo(PropertyInfoVO propertyInfo) {
this.propertyInfo = propertyInfo;
}
public String getMarshaCode() {
return marshaCode;
}
public void setMarshaCode(String mCode) {
this.marshaCode = mCode;
}
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="com.vo.PropertyVO" table="property" >
<comment></comment>
<id name="propertyId" type="long">
<column name="property_id" />
<generator class="sequence">
<param name="sequence">Seq_Property_ID</param>
</generator>
</id>
<one-to-one name="propertyInfo"
class="com.generalinfo.vo.PropertyInfoVO"
cascade="save-update"/>
<property name="marshaCode" type="string">
<column name="Marsha_Code" length="5"/>
</property>
</class>
</hibernate-mapping>
PropertyInfoVO shares a primary key with the PropertyVO. The following are the code and mapping files for PropertyInfoVO:
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="com.generalinfo.vo.PropertyInfoVO"
table="PROPERTY_INFO">
<id name="propertyId" type="long">
<column name="PROPERTY_ID" />
<generator class="foreign">
<param name="property">property</param>
</generator>
</id>
<one-to-one name="property"
class="com.vo.PropertyVO"
constrained="true"/>
<property name="propertyNameDisplay" type="string">
<column name="PROPERTY_NAME_DISPLAY" length="100"/>
</property>
</class>
</hibernate-mapping>
When I make a get call on the org.hibernate.Session (i.e., session.get(PropertyVO.class, id)), the following sql is executed against the database:
Code:
/* load com.vo.PropertyVO */ select
propertyvo0_.property_id as property1_26_1_,
propertyvo0_.Marsha_Code as Marsha2_26_1_,
propertyin1_.PROPERTY_ID as PROPERTY1_27_0_,
propertyin1_.PROPERTY_NAME_DISPLAY as PROPERTY2_27_0_
from
property propertyvo0_
left outer join
PROPERTY_INFO propertyin1_
on propertyvo0_.property_id=propertyin1_.PROPERTY_ID
where
propertyvo0_.property_id=?
According to the Hibernate reference documentation, if constrained="false", proxying is impossible and Hibernate will eager fetch the association. I'm assuming then that if constrained="true", lazy loading is possible. Since lazy defaults to "proxy" I thought that the PropertyInfoVO would be a proxy.
Am I missing something here? Why can I not get the PropertyInfoVO to be a proxy? Why is an eager fetch always being performed?
Thanks,
Sean