-->
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.  [ 4 posts ] 
Author Message
 Post subject: versioning (timestamp) problem
PostPosted: Fri Apr 29, 2005 4:22 am 
Newbie

Joined: Fri Apr 29, 2005 3:55 am
Posts: 2
hi, we are experiencing a strange hibernate behaviour

here is the mapping
----- cut here ---------
<hibernate-mapping>
<class
name="it.infotn.stu.business.esercizi.businesslogic.businessobject.RequisitoBO"
table="STUTREQUISITO"
proxy="it.infotn.stu.business.esercizi.businesslogic.businessobject.IRequisitoBOAuto"
dynamic-update="true"
dynamic-insert="false"
mutable="true"
>

<id
name="idObj"
column="IDOBJ"
type="java.lang.Long"
>
<generator class="sequence">
<param name="sequence">NXTNBR</param>
</generator>
</id>

<timestamp
name="timeVar"
column="TTIMEVAR"
/>

<property
name="chiaveTipoRequisito"
type="java.lang.String"
update="true"
insert="true"
column="CHIAVETIPOREQUISITO"
not-null="true"
/>

<many-to-one
name="possessoreRequisiti"
class="it.infotn.stu.business.esercizi.businesslogic.businessobject.PossessoreRequisiti"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="IDPOSSESSOREREQUISITI"
not-null="true"
/>

<component
name="datoSistema"
class="it.infotn.common.component.DatoSistema"
>
<property
name="utenteInserimento"
type="java.lang.String"
update="true"
insert="true"
column="UTENTEINSERIMENTO"
not-null="true"
/>

<property
name="utenteModifica"
type="java.lang.String"
update="true"
insert="true"
column="UTENTEMODIFICA"
not-null="false"
/>

<property
name="dataInserimento"
type="java.util.Date"
update="true"
insert="true"
column="DATAINSERIMENTO"
not-null="true"
/>

<property
name="dataModifica"
type="java.util.Date"
update="true"
insert="true"
column="DATAMODIFICA"
not-null="false"
/>

</component>


<joined-subclass
name="it.infotn.stu.business.esercizi.businesslogic.businessobject.RequisitoValoreLiberoBO"
table="STUTREQUISITOVALORELIBERO"
dynamic-update="true"
dynamic-insert="true"
proxy="it.infotn.stu.business.esercizi.businesslogic.businessobject.IRequisitoValoreLiberoBOAuto"
>
<key
column="IDREQUISITO"
/>

<property
name="valoreRequisito"
type="java.lang.String"
update="true"
insert="true"
column="VALOREREQUISITO"
not-null="false"
/>

</joined-subclass>
<joined-subclass
name="it.infotn.stu.business.esercizi.businesslogic.businessobject.RequisitoValoreListaBO"
table="STUTREQUISITOVALORELISTA"
dynamic-update="true"
dynamic-insert="true"
proxy="it.infotn.stu.business.esercizi.businesslogic.businessobject.IRequisitoValoreListaBOAuto"
>
<key
column="IDREQUISITO"
/>

<property
name="chiaveValoreTipoRequisito"
type="java.lang.String"
update="true"
insert="true"
column="CHIAVEVALORETIPOREQUISITO"
not-null="true"
/>

</joined-subclass>

</class>
</hibernate-mapping>
-------------------- cut here ---------------------
when we do a cascade delete:

session.delete("from RequisitoBO as r where r.possessoreRequisiti.idObj = ?", idPossessore, Hibernate.LONG);
session.flush();

if the timestamp we use for versioning , on db, is: xx:xx:xx,0000000000 we get a staleObjectException even if the data is fresh, we've tried to do:

List l= session.find("from RequisitoBO as r where r.possessoreRequisiti.idObj = ?", idPossessore,
Hibernate.LONG);

before the delete and we got a different timestamp ! We are (almost) sure there aren't two sessions writing tha same data on db

anyone can help?

thanx


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 9:22 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
It probably has to do with the granularity of the timestamp. I had the same problem using a <version type="timestamp"> mapped to a java.util.Date property. java.util.Date stores the date to the millisecond, while the Oracle TIMESTAMP column by default stores to the microsecond (and can go all the way down to the nanosecond). I had to convert my java.util.Date property to java.sql.Timestamp to ensure that the microseconds were not truncated when loading the data from the database. The other option would be to change all of my TIMESTAMP columns to TIMESTAMP(3) to reduce Oracle's granularity to milliseconds.

It could also have to do with timezone offsets and whatnot. Oracle has TIMESTAMPE WITH [LOCAL] TIMEZONE that will store the GMT offset with the time...if that doesn't jive with whatever's in the POJO then you'll wind up with the same problem.

- Jesse


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 10:19 am 
Newbie

Joined: Fri Apr 29, 2005 3:55 am
Posts: 2
Quote:
It probably has to do with the granularity of the timestamp. I had the same problem using a <version type="timestamp"> mapped to a java.util.Date property
It could also have to do with timezone offsets and whatnot. Oracle has TIMESTAMPE WITH [LOCAL] TIMEZONE


another clue, if we do a session.refresh before the delete, the timestamp is reloaded from the DB and everything works as expected, this problem only occurs when the timestamp on db ends with 0000000000 (if not it works even without refresh, the probability it happens is low I know)

doesn't seem a timestamp handling problem



our db is oracle and we've the latest hibernate 2.x


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 02, 2005 10:48 am 
Regular
Regular

Joined: Mon Jul 26, 2004 2:28 pm
Posts: 86
Location: Pensacola, Florida
I didn't read your first post closely enough (I didn't see the bit about the timstamp changing in the find). First thing I would try is to set an unsaved-value in the <timestamp> tag...I've had some problems with that before. Next, look do see if you have a default value for the timestamp column (I don't really see how this would come into play as Hibernate should. Last, make sure there aren't any triggers that would affect the timestamp column.

Are the save/delete occurring in the same Hibernate session? If not, then a session.lock( object, LockMode.NONE ) or session.update( object ) is a good idea anyway (especially if you are using lazy initialization). If so, then the culprit has to be another Hibernate session or something in the database.


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