-->
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.  [ 27 posts ]  Go to page Previous  1, 2
Author Message
 Post subject:
PostPosted: Wed Feb 23, 2005 4:14 pm 
Beginner
Beginner

Joined: Fri Feb 11, 2005 2:40 pm
Posts: 27
max wrote:
it works fine in the hibernate 3 unit tests...have you played around with those to see it work ?


No because I coudn't find which one uses lazy loading for a property. Do you know which one?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 4:51 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i've run other tests with lazy properties, it works for me too

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 5:30 pm 
Beginner
Beginner

Joined: Fri Feb 11, 2005 2:40 pm
Posts: 27
anthony wrote:
i've run other tests with lazy properties, it works for me too


OK, I found "instrument" test case that I think is supposed to test lazy loading of a property. In the mapping file that comes with HB test case the "name" property is not lazy loaded. The "summary" is. So my understanding is that when you load the object the summary property should not be in the first SELECT on the object. So either the instrumentation failed or there's some other kind of a problem, but the bottom line is that even though the test case doesn't fail the property is not lazily loaded. Or I'm messing something up.

UPDATED TEST CASE
s = openSession();
doc = (Document) s.createQuery("from Document").uniqueResult();

System.out.println("*** got doc = ");

doc.getName();
System.out.println("** got name = " + doc.getName());

assertEquals( doc.getText(), "blah blah" );
System.out.println("** got text = " + doc.getText());

assertEquals( doc.getSummary(), "blah" );

System.out.println("** summary = " + doc.getSummary());

s.connection().commit();
s.close();



DEBUG OUTPUT
16:07:13,085 DEBUG SQL:292 - select document0_.id as id, document0_.name as name2_, document0_.folder as folder2_ from documents document0_
*** got doc =
** got name = Hibernate in Action
16:07:13,596 DEBUG SQL:292 - select document_.summary as summary2_, document_.owner as owner2_, document_.text as text2_, document_.lastTextModification as lastText7_2_, upper(document_.name) as formula0_ from documents document_ where document_.id=?
16:07:13,907 DEBUG SQL:292 - select owner0_.id as id0_, owner0_.name as name1_0_ from owners owner0_ where owner0_.id=?
** got text = blah blah
** summary = blah


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 23, 2005 7:51 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
FYI, I am *quite* sure that this is working. And even your own SQL log seems to show it is working for *you*...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 4:02 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
i've updated my cvs this morning, i'll run another test tonight.
But xplorem, confirm that you still have a bug with latest source (+homebuild, we don't know) + instrumentation

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 2:26 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all tests run fine... even with my "crazy" little mapping file (lazy attribute in a join element):



Code:
<hibernate-mapping package="com.eyrolles.sportTracker.model">

<class name="EhancedTeam" table="TEAM" >
   <id name="id" column="TEAM_ID">
      <generator class="native"/>
   </id>
   <bag name="players" inverse="true" fetch="select" cascade="persist,merge">
      <key column="TEAM_ID"/>
      <one-to-many class="EhancedPlayer" />
   </bag>
   <property name="nbLost" column="NB_LOST" lazy="true"/>
   <property name="name" column="TEAM_NAME" lazy="true"/>
   <!--many-to-one column="SPONSOR_ID" lazy="true" name="sponsor"/-->
   <join table="COACH" >
      <key column="TEAM_ID"/>
      <property name="coachName" column="COACH_NAME" lazy="true"/>
      <property name="coachWeight" column="WEIGHT" lazy="true"/>
      <property name="coachHeight" column="HEIGHT" lazy="true"/>
      <property name="coachBirthday" column="BIRTHDAY" lazy="true"/>
   </join>
</class>
</hibernate-mapping>

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Got it
PostPosted: Thu Feb 24, 2005 4:00 pm 
Beginner
Beginner

Joined: Fri Feb 11, 2005 2:40 pm
Posts: 27
anthony wrote:
i've updated my cvs this morning, i'll run another test tonight.
But xplorem, confirm that you still have a bug with latest source (+homebuild, we don't know) + instrumentation


I spend almost half a day trying to figure out why lazy loading doesn't work. Well, I finally got the sucker so check it out.

It appears that if an instance variable for the lazy property starts with the "_" then the lazy loading is not working. If it doesn't start with _, it's working fine! You can reproduce it with your own test case InstrumentTest by renaming field "text" of the Document class to "_text" and leaving methods getText() and setText(). The mapping file does not say "access=field" so as I understand by default it should be access=property.

Is this a bug that is going to be fixed or is some peculiar expected behavior?? Sounds like a bug to me.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 5:23 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
It works as expected, enhancer transforms all methods in the same way (replaces field access with callback) it needs to know field names for this stuff, method names have no meaning for this type of transformation and there is no workaround (hibernate doe's not know your field names too).


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 24, 2005 5:38 pm 
Beginner
Beginner

Joined: Fri Feb 11, 2005 2:40 pm
Posts: 27
baliukas wrote:
It works as expected, enhancer transforms all methods in the same way (replaces field access with callback) it needs to know field names for this stuff, method names have no meaning for this type of transformation and there is no workaround (hibernate doe's not know your field names too).


Here is why I think it should be classified as a bug:

- The same code works when the lazy=false and doesn't when lazy=true. This can not be expected behavior.

- If lazy loading of properties operates directly on fields, then the enhancer should check the class for fields with an expected name and throw an exception if there is no field matching the property name.

So I guess what I'm saying is that either it should work for all access types (method, field etc.) or it should throw an exception if it knows that it wouldn't work. Makes sense?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 2:41 am 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
There is no way to find field name by property name, but it is possible to validate this stuff.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 12:43 pm 
Beginner
Beginner

Joined: Fri Feb 11, 2005 2:40 pm
Posts: 27
baliukas wrote:
There is no way to find field name by property name, but it is possible to validate this stuff.


Just out of curiosity, isn't it possible to intercept a getter method call to get the property, make the database call, and set the property value using the setter? Same thing as with the value but it would support all access strategies for a property - as recommended in Hibernate documentation: "Many other ORM tools directly persist instance variables. We believe it is far better to decouple this implementation detail from the persistence mechanism. Hibernate persists JavaBeans style properties, and recognizes method names of the form getFoo, isFoo and setFoo. You may however switch to direct field access for particular properties, if needed. "

Also, what are your guys thoughts on session reattachment? The way we are planning to use lazy properies is as follows. We have a table with large number of rows that shows only the summary inforamtion about the person (say name, age and data of birth). If a user clicks on the table row, we show the entire person's profile which includes the picture (BLOB), long text description fields and so on. I would think that's typical for lazy loading - to have some data retreived in one request and more data at some point later but NOT ON THE SAME SESSION (because we are going to close the session when the first request is processed). It sounds like to make lazy loading work we'd have to reattach the objects to the new session by calling update() or lock(). That is not very intuitive. Have you thought of associating the session with the thread and maybe using that for lazy loading?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 25, 2005 1:40 pm 
CGLIB Developer
CGLIB Developer

Joined: Thu Aug 28, 2003 1:44 pm
Posts: 1217
Location: Vilnius, Lithuania
xplorem wrote:
baliukas wrote:
There is no way to find field name by property name, but it is possible to validate this stuff.


Just out of curiosity, isn't it possible to intercept a getter method call to get the property, make the database call, and set the property value using the setter? Same thing as with the value but it would support all access strategies for a property - as recommended in Hibernate documentation: "Many other ORM tools directly persist instance variables. We believe it is far better to decouple this implementation detail from the persistence mechanism. Hibernate persists JavaBeans style properties, and recognizes method names of the form getFoo, isFoo and setFoo. You may however switch to direct field access for particular properties, if needed. "


No, it is not the same thing with field interception strategy, but probably it is too long story for forum message. I see current enhancer implementation doe's not use mapping files, it can not to validate too.

As remember "auto-reattachment" was discussed many times, it is trivial to implement it, but it is "dangerous". Probably it is not a problem to reread row in your case too, you have id and need to hit database/cache anyway. As I understand lazy properties do not use global cache, it can be important for this use case too.

<out-of-topic>
BTW I have added jar file support and filtering by "magic" number. "getTransformer" was changed to use array of class and interface names, it will help to remove custom class file visitor to detect duplicate enhancement (you need to remove it for jar file enhancement support).
Code:

if ( Arrays.asList(names).contains( INTERCEPT_ENABLED ) ) return null; 

</out-of-topic>


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

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.