-->
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.  [ 3 posts ] 
Author Message
 Post subject: version update when performing a select
PostPosted: Thu Sep 14, 2006 10:56 am 
Newbie

Joined: Thu Jul 06, 2006 8:04 am
Posts: 14
I've got lazy loading collections working fine in other areas on the same code, but I can't figure out why a select on a Licence class which has a lazy=true one-to-many collection would result in a version update on Licence? I don't actually want the collection, and the collection is not brought back as can be seen in the log ([com.med.dom.Licence.points#1] (uninitialized)), but then AbstractFlushingEventListener says there is 1 update - within miliseconds of each other in the log??

Its been half a day now on this and I need some help!

Thanks,
adam

hql: from License where entitiyId = x;

2006-09-14 15:33:05,312 DEBUG [org.hibernate.engine.TwoPhaseLoad] - done materializing entity [com.med.dom.Licence#1]
2006-09-14 15:33:05,312 DEBUG [org.hibernate.engine.StatefulPersistenceContext] - initializing non-lazy collections
2006-09-14 15:33:05,312 DEBUG [org.hibernate.jdbc.ConnectionManager] - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!
2006-09-14 15:33:05,312 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - processing flush-time cascades
2006-09-14 15:33:05,312 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - dirty checking collections
2006-09-14 15:33:05,312 DEBUG [org.hibernate.engine.Collections] - Collection found: [com.med.dom.Licence.points#1], was: [com.med.dom.Licence.points#1] (uninitialized)
2006-09-14 15:33:05,312 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - Flushed: 0 insertions, 1 updates, 0 deletions to 1 objects
2006-09-14 15:33:05,312 DEBUG [org.hibernate.event.def.AbstractFlushingEventListener] - Flushed: 0 (re)creations, 0 updates, 0 removals to 1 collections
2006-09-14 15:33:05,312 DEBUG [org.hibernate.pretty.Printer] - listing entities:
2006-09-14 15:33:05,328 DEBUG [org.hibernate.pretty.Printer] - com.med.dom.Licence{roadSideExpiry=component[day,month,year]{month=null, day=null, year=null}, usersId=10, type=, notes=null, algorithm=null, points=<uninitialized>, id=1, roadSideCalloutNumber=null, version=6, internationalNumber=null, noClaimsStart=component[day,month,year]{month=null, day=null, year=null}, roadSideAccount=null, roadSideNumber=null, name=test54, roadSideInsurer=null, number=}
2006-09-14 15:33:05,328 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
2006-09-14 15:33:05,328 DEBUG [org.hibernate.SQL] - update licences set version=?, usersId=?, algorithm=?, name=?, type=?, number=?, internationalnumber=?, noclaimsstartday=?, noclaimsstartmonth=?, noclaimsstartyear=?, roadsideinsurer=?, roadsideaccount=?, roadsidenumber=?, roadsidecalloutnumber=?, roadsideexpiryday=?, roadsideexpirymonth=?, roadsideexpiryyear=?, notes=? where id=? and version=?
2006-09-14 15:33:05,359 DEBUG [org.hibernate.jdbc.AbstractBatcher] - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
2006-09-14 15:33:05,359 DEBUG [org.hibernate.jdbc.ConnectionManager] - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
2006-09-14 15:33:05,359 DEBUG [org.hibernate.jdbc.ConnectionManager] - transaction completed on session with on_close connection release mode; be sure to close the session to release JDBC resources!


mapping file:

<class name="Licence" table="licences" lazy="true">

<id name="id" column="id" type="long" unsaved-value="null">
<generator class="identity"/>
</id>
<version name="version"/>

...

<set name="points" cascade="all-delete-orphan" lazy="true" inverse="true" order-by="id asc">
<key column="licencesId"/>
<one-to-many class="LicencePoint"/>
</set>


Top
 Profile  
 
 Post subject: think I've sussed it
PostPosted: Thu Sep 14, 2006 1:14 pm 
Newbie

Joined: Thu Jul 06, 2006 8:04 am
Posts: 14
I believe because of the subtleness of the 'error' - in that it is not an error I just had noticed the version numbers changing all the time - I had not noticed the change when I upgraded from a previous version.

In the old version (2?) I did things like:

public void setBirthdate(MedDate birthdate) {
if (birthdate == null) this.birthdate = new MedDate();
else this.birthdate = birthdate;
}

because my view would complain when the component was null. So when hibernate assigns a null component, it actually creates an object with null default values.

In the new version (3.2) it appears that hibernate now detects this as a change, and hence the version changes when none of the data appears to (because the new value also contains nulls!)

So it was nothing to do with the collection after all.

Phew!


Top
 Profile  
 
 Post subject: solution
PostPosted: Fri Sep 15, 2006 5:41 am 
Newbie

Joined: Thu Jul 06, 2006 8:04 am
Posts: 14
in case people are unsure what solutiuon I did....(heopfully others can comment of the approach)


in the mapping file:

<component ... access="field">

in the java file:

change

public void setBirthdate(MedDate birthdate) {
if (birthdate == null) this.birthdate = new MedDate();
else this.birthdate = birthdate;
}

to be along the lines of a normal bean property accessor

set...(...) {
this.prop = that;
}

but change the get to be (obviously ignore the actual method names):

public MedDate getNoClaimsStart() {
if (noClaimsStart == null) this.noClaimsStart = new MedDate();
return noClaimsStart;
}

that way hibernate is happy the views are happy (that there is no null object) and I am happy!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.