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.
|