Hi,
I'm trying to verify if transaction demarcations works.
I'm using hibernate-3.2.6.GA in JDBC Transaction.
This is my Java code:
Code:
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
try {
sessionFactory.getCurrentSession().beginTransaction();
// I build a Query object
Query q = sessionFactory.getCurrentSession().createQuery("update SceneElement sceneElement set
sceneElement.sequence=(-1)*sceneElement.sequence where sceneElement.scene.id=? and
sceneElement.sequence>=?")
.setParameter(0, 144)
.setParameter(1, 0);
// I execute an update statement
q.executeUpdate();
// I throw an exception before the transaction commit
if (true) throw new Exception("I want you rollback!");
sessionFactory.getCurrentSession().getTransaction().commit();
}catch (Throwable e) {
sessionFactory.getCurrentSession().getTransaction().rollback();
e.printStackTrace();
}
This is my hibernate.cfg.xml
Code:
<hibernate-configuration>
<session-factory>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/db</property>
<property name="connection.username">root</property>
<property name="connection.password">xxx</property>
<property name="connection.autocommit">false</property>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="show_sql">true</property>
<property name="transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
<property name="current_session_context_class">thread</property>
<mapping resource="xxx.SceneElement.hbm.xml"/>
</session-factory>
</hibernate-configuration>
The entity SceneElement contains two joined-subclassMy problem is:
when I execute the update statement:
Code:
q.executeUpdate();
database is updated.
This isn't what I expected, because I don't commit transaction and I call a rollback.
With others entities transactions works fine, but with joined-subclass updates are performed outside transaction.
Where I'm wrong?
It's a bug?
Thanks.
Pierpaolo.