-->
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.  [ 1 post ] 
Author Message
 Post subject: idbag causes inefficient database sync
PostPosted: Tue May 29, 2007 8:30 am 
Newbie

Joined: Tue May 29, 2007 8:09 am
Posts: 1
Hi folks,

Hibernate version: 3.2

Tried to make the following simple idbag mapping:

<class name="Account" table="ACCOUNT">
<id name="id" column="ID_ACCOUNT">
<generator class="native"/>
</id>
<property name="code"
type="string"
length="10"
not-null="true"
unique="true"
/>

<idbag name="statements" table="STATEMENT" >
<collection-id type="long" column="ID_STATEMENT">
<generator class="sequence" />
</collection-id >
<key column="ID_ACCOUNT" not-null="true"/>
<composite-element class="Statement">
<parent name="account" />
<property name="date" type="timestamp" not-null="true" />
<property name="amount" type="double" not-null="true" />
<property name="description" type="string" length="100" />
</composite-element>
</idbag>
</class>

and then used the following code to check:
------------------------------------------------------
Session s1 = me.getCurrentSession();
s1.beginTransaction();

Account a = new Account("001");
a.addStatement(new Statement(new Date(), 10, "first"));
a.addStatement(new Statement(new Date(), -9, "second"));
Long aid = (Long) s1.save(a);

s1.getTransaction().commit();
me.log("fresh session");

Session s2 = me.getCurrentSession();
s2.beginTransaction();

Account a1 = (Account) s2.get(Account.class, aid);
me.log("stmts" + a1.getStatements());

s2.getTransaction().commit();
------------------------------------------------------
I noticed that even in case of using <collection-id> element,
the idbag always tries to remove ALL collection elements
from database and the re-insert them even without ANY modification.
Which is strange. Here is the output:
------------------------------------------------------
Hibernate: insert into V1.ACCOUNT (ID_ACCOUNT, code) values (default, ?)
Hibernate: values identity_val_local()
Hibernate: values nextval for V1.hibernate_sequence
Hibernate: values nextval for V1.hibernate_sequence
Hibernate: insert into V1.STATEMENT (ID_ACCOUNT, ID_STATEMENT, date, amount, description) values (?, ?, ?, ?, ?)
Hibernate: insert into V1.STATEMENT (ID_ACCOUNT, ID_STATEMENT, date, amount, description) values (?, ?, ?, ?, ?)
###main: fresh session
Hibernate: select account0_.ID_ACCOUNT as ID1_3_0_, account0_.code as code3_0_ from V1.ACCOUNT account0_ where account0_.ID_ACCOUNT=?
Hibernate: select statements0_.ID_ACCOUNT as ID1_0_, statements0_.date as date0_, statements0_.amount as amount0_, statements0_.description as descript4_0_, statements0_.ID_STATEMENT as ID5_0_ from V1.STATEMENT statements0_ where statements0_.ID_ACCOUNT=?
###main: stmtsorg.hibernate.collection.PersistentIdentifierBag@66ce66ce
Hibernate: delete from V1.STATEMENT where ID_ACCOUNT=?
Hibernate: values nextval for V1.hibernate_sequence
Hibernate: values nextval for V1.hibernate_sequence
Hibernate: insert into V1.STATEMENT (ID_ACCOUNT, ID_STATEMENT, date, amount, description) values (?, ?, ?, ?, ?)
Hibernate: insert into V1.STATEMENT (ID_ACCOUNT, ID_STATEMENT, date, amount, description) values (?, ?, ?, ?, ?)
###main: *** STOP ***
------------------------------------------------------

Can anyone explain me why this happens ?

Regards,
/Alexander


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.