-->
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: Session.isDirty() perfoms save ?
PostPosted: Thu Oct 27, 2005 10:13 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
Hi,

When calling Session.isDirty() (Hibernate 3.0.5, non-classic) Hibernate performs implicitly a save and generates the SQL for retrieving the new id (from the sequence).

Here is my example:

Session ses=SessionManager.currentSession();
TblDocumenti doc = (TblDocumenti)ses.load(TblDocumenti.class, new Long(506));
TblSequenze seq = (TblSequenze)TblSequenze.class.newInstance();
seq.setDoc(doc);
seq.setSezione(new Short("2"));

doc.getTblSequenze().add(seq);

// if you omit the following line the id is retrieved when calling flush
if (ses.isDirty()) {System.out.println("isDirty");} // The previous call performs a save and a call to nextvalue of the sequence

Transaction t = ses.beginTransaction();
ses.flush();
t.commit();

Here are the xml files:
TblDocumenti:
<class dynamic-update="true" lazy="false" name="TblDocumenti"
schema="GAM_ADM" table="TBL_DOCUMENTI">
<id name="id" type="long">
<column index="PK_TBL_DOCUMENTI" name="ID" not-null="true"
precision="11" scale="0"/>
<generator class="sequence">
<param name="sequence">S_470_1_TBL_DOCUMENTI</param>
</generator>
</id>
<version column="VERSION" name="version" type="integer"/>
<property column="xxx" lazy="false" name="xxx" type="string"/>
</property>
<bag access="field" cascade="save-update" inverse="true" lazy="true" name="tblSequenze">
<key foreign-key="TBL_SEQ_DOC">
<column index="DOC_ID" name="DOC_ID" not-null="true" precision="11" scale="0"/>
</key>
<one-to-many class="" entity-name="microfilm.model.TblSequenze" />
</bag>
</class>

TblSequenze
<class name="TblSequenze" lazy="false" table="TBL_SEQUENZE" schema="GAM_ADM" optimistic-lock="none" dynamic-update="true">
<id name="id" type="long" unsaved-value="null">
<column name="ID" precision="11" scale="0" not-null="true" index="ID"/>
<generator class="sequence" >
<param name="sequence">S_473_1_TBL_SEQUENZE</param>
</generator>
</id>
<property name="sezione" type="short">
<column name="SEZIONE" precision="5" scale="0"/>
</property>
<many-to-one lazy="false" access="field" name="doc" entity-name="microfilm.model.TblDocumenti" cascade="none" foreign-key="TBL_SEQ_DOC">
<column name="DOC_ID" precision="11" scale="0" not-null="true" index="DOC_ID"/>
</many-to-one>
</class>

Thank U very much
Simone


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 28, 2005 4:40 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
Is it correct behaviour the a call to session.isDirty performs call to save (genrating sql for retrieving id value from sequence) ?
Thanks


Top
 Profile  
 
 Post subject: isDirty() bug ??
PostPosted: Thu Nov 03, 2005 6:02 am 
Newbie

Joined: Thu Dec 16, 2004 12:56 pm
Posts: 9
I suppose it's a bug


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.