Dear all
I read the book "Java Persistence with Hibernate"
In page 407, it says that if you enable the hibernat.use_identifier_rollback configuration option.Hibernate sets the database identifier property of the deleted item to null after deletion and flushing.
I want to try this feature but it can't work.
The code and hibernate configuration as below.
Can someone help me to see if there are any problem?
Code:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
"-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!-- Generated by MyEclipse Hibernate Tools. -->
<hibernate-configuration>
<session-factory>
<property name="dialect">
org.hibernate.dialect.Oracle9Dialect
</property>
<property name="connection.url">
jdbc:oracle:thin:@localhost:1521:TESTDB
</property>
<property name="connection.username">abc</property>
<property name="connection.password">123</property>
<property name="connection.driver_class">
oracle.jdbc.driver.OracleDriver
</property>
<property name="hibernate.use_identifier_rollback">true</property>
<mapping resource="com/test/Item.hbm.xml" />
</session-factory>
</hibernate-configuration>
Code:
public static void main( String[] args )
{
Session session = HibernateSessionFactory.getSession();
Transaction tx = session.beginTransaction();
Item item = (Item)session.load( Item.class , new Long(1) );
session.delete( item );
tx.commit();
System.out.println( item.getItemId()); //The PK item_id is not set to null
session.close();
}