-->
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: executeUpdate() ignores transaction with joined-subclass ??
PostPosted: Thu Dec 31, 2009 9:47 am 
Newbie

Joined: Thu Dec 31, 2009 9:09 am
Posts: 1
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-subclass

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


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