I have a very basic query that should just get my PaperworkFolder object but for some reason Hibernate seems to also be executing SQL to retrieve my Employee object even though I have not accessed that member variable.
I notice that it retrieves the Employee object the first time the Paperwork object it retrieved but not the second time (I'm guessing it is caching it so it doesn't need to get it the second time).
How do I get Hibernate to not retrieve my Employee object until I reference it on the first try?
Hibernate version: 3.2
Mapping documents:
Code:
PaperworkFolder.hbm.xml
<hibernate-mapping package="com.ptilabs.commons.domain.paperwork" schema="V2">
<class name="PaperworkFolder" table="PW_FOLDER">
<id name="id" column="PW_FOLDER_ID" type="long">
<generator class="native">
<param name="sequence">PW_FOLDER_SEQ</param>
</generator>
</id>
<property name="label" column="LABEL" not-null="true" />
<many-to-one name="entryCreator"
column="ENTRY_CREATOR_ID" />
</class>
</hibernate-mapping>
Employee.hbm.xml
<hibernate-mapping package="com.ptilabs.commons.domain.user" schema="V2">
<class name="Employee" table="EMPLOYEE_ST">
<id name="id" column="EMPLOYEE_ID" type="long">
<generator class="native">
<param name="sequence">EMPLOYEE_SEQ</param>
</generator>
</id>
<property name="userName" column="USER_NAME" not-null="true"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():Code:
Query q = ((Session)r.getDataProvider()).createQuery("from PaperworkFolder p where p.label = :label");
q.setParameter("label", "TEST");
List list = q.list();
Name and version of the database you are using: Oracle 9.x
The generated SQL (show_sql=true):Code:
Hibernate: select paperworkf0_.PW_FOLDER_ID as PW1_98_, paperworkf0_.LABEL as LABEL98_, paperworkf0_.ENTRY_CREATOR_ID as ENTRY3_98_ from V2.PW_FOLDER paperworkf0_ where paperworkf0_.LABEL=?
Hibernate: select employee0_.EMPLOYEE_ID as EMPLOYEE1_157_0_, employee0_.USER_NAME as USER2_157_0_ from V2.EMPLOYEE_ST employee0_ where employee0_.EMPLOYEE_ID=?