-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Lazy Loading loading untouched entities
PostPosted: Fri Nov 30, 2007 4:13 pm 
Newbie

Joined: Fri Nov 30, 2007 4:00 pm
Posts: 4
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=?


Top
 Profile  
 
 Post subject: Got it
PostPosted: Fri Nov 30, 2007 5:01 pm 
Newbie

Joined: Fri Nov 30, 2007 4:00 pm
Posts: 4
Never mind. I got it working. There was an issue in the actual object. It was referencing the Employee object on loading


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.