-->
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: session.isDirty() bug??
PostPosted: Fri Nov 04, 2005 5:14 am 
Newbie

Joined: Thu Dec 16, 2004 12:56 pm
Posts: 9
Hi,

When calling Session.isDirty(), after inserting a new pojo instance in the collection, Hibernate performs implicitly a save of the transient object and generates the SQL for retrieving the new id (from the sequence). Is it a bug??


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 8:17 am 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
That depends on the cascade mapping declaration of your collection. See the reference manual chapter 22.

HTH
Ernst


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 9:18 am 
Beginner
Beginner

Joined: Fri Nov 19, 2004 11:38 am
Posts: 29
I read this chapter, but there is not mentioned that is correct behaviour that a call to session.isDirty performs save.
The problem is that when i call session.isDirty a save operation is fired even if it's not necessary.
Here is my short example:
Posted: Thu Oct 27, 2005 2:13 pm Post subject: Session.isDirty() perfoms save ?

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>

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 04, 2005 4:43 pm 
Expert
Expert

Joined: Thu Jan 29, 2004 2:31 am
Posts: 362
Location: Switzerland, Bern
Guess you didn't change the default flush mode of the session (auto). This means hibernate is allowed to sync the session to the DB when ever it "thinks" it's a good idea to do so.

HTH
Ernst


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.