-->
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: unnecessary update instead of an insert
PostPosted: Fri Oct 28, 2005 9:54 pm 
Newbie

Joined: Wed Oct 26, 2005 4:57 pm
Posts: 5
Hi,

A little question about the dirty checking before updating a newly add Object.

Hibernate version:
3.1 rc2

Mapping documents:
<class name="Bob" table="Bob" dynamic-update="true">
<id name="id" column="id">
<generator class="sequence">
<param name="sequence">bob_seq</param>
</generator>
</id>

<property name="simple"/>
<property name="t" type="date"/>
</class>

Code between sessionFactory.openSession() and session.close():
Bob bob = new Bob();

Bob.setSimple("test me");
bob.setT(new Date(System.currentTimeMillis()));

Serializable id = sess.save(bob);

bob.setSimple("No ... ");
tran.commit();

The generated SQL (show_sql=true):
Hibernate: select bob_seq.nextval from dual
Hibernate: insert into Bob (b, simple, t, id) values (?, ?, ?, ?)
Hibernate: update Bob set simple=? where id=?

What i tought should happen is that the engine will discover the fact the it hasn't done the INSERT and will make only it with the final values.

I saw that in the DefaultFlushEntityEventListener Class the [b]onFlushEntity[/] method doesn't check if the entity that is already about to be inserted it simply calls the isUpdateNecessary and if so schedule a new Update.

Is this the expected beavior ?
or is there a property / attribute i can use ?

thanx.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 3:12 pm 
Newbie

Joined: Wed Oct 26, 2005 4:57 pm
Posts: 5
another try ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 01, 2005 7:27 pm 
Regular
Regular

Joined: Fri Sep 09, 2005 11:35 am
Posts: 101
you would not have the "id" if hibernate had not executed the insert so i would think this is expected. otherwise do not call save and there should be only the insert statement.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2005 6:45 pm 
Newbie

Joined: Wed Oct 26, 2005 4:57 pm
Posts: 5
ofcourse hibernate executed the insert ...

I really don't think this behavior should be expected.

This is just a simple example of a change that occurs in the persistent object right after it was saved.

The code that changed the persistent object shouldn't be aware of its synchorinzed state, but still hibernate SHOULD be and not do an update when it isn't neccessry ..

someone has a real idea way this happens ?


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.