-->
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.  [ 3 posts ] 
Author Message
 Post subject: [JTA] UserTransaction doesn't commit or rollback
PostPosted: Sun Nov 07, 2010 9:03 am 
Newbie

Joined: Sun Nov 07, 2010 8:14 am
Posts: 3
Hi all,

I'm using JTA in the following scenario:

* Glassfishv2.1

* hibernate dependencies:
Code:
       <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.4.0.GA</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>3.2.4.GA</version>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>3.4.0.GA</version>
            <scope>compile</scope>
        </dependency>


* persistence.xml
Code:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd">
  <persistence-unit name="BluManager" transaction-type="JTA">
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
  </persistence-unit>
</persistence>


* persistence.properties
Code:
hibernate.show_sql=true
hibernate.connection.username=root
hibernate.connection.password=
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=none
hibernate.connection.url=jdbc:mysql://localhost/database?autoReconnect=true
hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider
hibernate.c3p0.min_size=0
hibernate.c3p0.max_size=30
hibernate.c3p0.timeout=600
hibernate.c3p0.max_statements=0
hibernate.c3p0.acquire_increment=1
hibernate.c3p0.idle_test_period=60

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.region.jbc2.query.localonly=true
hibernate.cache.region.factory_class=org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory
hibernate.cache.region.jbc2.cfg.shared=treecache.xml

hibernate.transaction.manager_lookup_class=org.hibernate.transaction.SunONETransactionManagerLookup
hibernate.current_session_context_class=jta


* Obtaining the EntityManagerFactory:
Code:
String persistenceName = "PersistenceManager";
managerFactory = Persistence.createEntityManagerFactory(persistenceName,
                properties);


* Obtaining the UserTransaction:
Code:
UserTransaction utx =
                (javax.transaction.UserTransaction) new javax.naming.InitialContext().
                lookup("UserTransaction");


* Persisting example:
Code:
utx.begin();
EntityManager manager =  managerFactory.createEntityManager(map);
Category c = new Category("c1");
manager.persist(c);
utx.rollback();
manager.close();

utx.begin();
EntityManager manager =  managerFactory.createEntityManager(map);
Category c = new Category("c2");
manager.persist(c);
utx.commit();
manager.close();




With this, both entities are commited to database, utx.rollback() doesn't seem to work.

If I add to persistence.properties this line:
Code:
hibernate.connection.autocommit=false

both entities aren't commited to database. I have verified that the EntityManager joins the JTA transaction.

Can somebody help me? The log doesn't show any exception.
Thanks


Top
 Profile  
 
 Post subject: Re: [JTA] UserTransaction doesn't commit or rollback
PostPosted: Sun Nov 07, 2010 3:20 pm 
Newbie

Joined: Sun Nov 07, 2010 8:14 am
Posts: 3
This is the log without autocommit:
Quote:
20:16:19,821 DEBUG SessionImpl:247 - opened session at timestamp: 12891573798
20:16:19,822 DEBUG AbstractEntityManagerImpl:439 - Looking for a JTA transaction to join
20:16:19,822 DEBUG JDBCContext:199 - successfully registered Synchronization
20:16:19,862 DEBUG AbstractSaveEventListener:320 - executing identity-insert immediately
20:16:19,864 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
20:16:19,865 DEBUG ConnectionManager:444 - opening JDBC connection
20:16:19,867 DEBUG SQL:111 - insert into Category (name, parent) values (?, ?)
Hibernate: insert into Category (name, parent) values (?, ?)
20:16:19,872 DEBUG IdentifierGeneratorFactory:95 - Natively generated identity: 119
20:16:19,873 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
20:16:19,873 DEBUG ConnectionManager:427 - aggressively releasing JDBC connection
20:16:19,874 DEBUG ConnectionManager:464 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
20:16:19,949 DEBUG ReceptionFilter:67 - Packet from aj2r.fidesol@gmail.com/60a180a6
20:16:19,953 DEBUG SessionImpl:247 - opened session at timestamp: 12891573799
20:16:19,953 DEBUG AbstractEntityManagerImpl:439 - Looking for a JTA transaction to join
20:16:19,953 DEBUG JDBCContext:199 - successfully registered Synchronization
20:16:19,954 DEBUG AbstractSaveEventListener:320 - executing identity-insert immediately
20:16:19,954 DEBUG AbstractBatcher:410 - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
20:16:19,954 DEBUG ConnectionManager:444 - opening JDBC connection
20:16:19,955 DEBUG SQL:111 - insert into Category (name, parent) values (?, ?)
Hibernate: insert into Category (name, parent) values (?, ?)
20:16:19,956 DEBUG IdentifierGeneratorFactory:95 - Natively generated identity: 120
20:16:19,957 DEBUG AbstractBatcher:418 - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
20:16:19,957 DEBUG ConnectionManager:427 - aggressively releasing JDBC connection
20:16:19,958 DEBUG ConnectionManager:464 - releasing JDBC connection [ (open PreparedStatements: 0, globally: 0) (open ResultSets: 0, globally: 0)]
20:16:19,960 DEBUG AbstractFlushingEventListener:134 - processing flush-time cascades
20:16:19,961 DEBUG AbstractFlushingEventListener:177 - dirty checking collections
20:16:19,967 DEBUG AbstractFlushingEventListener:108 - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
20:16:19,968 DEBUG AbstractFlushingEventListener:114 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
20:16:19,970 DEBUG Printer:106 - listing entities:
20:16:19,970 DEBUG Printer:113 - es.blusolutions.blupersistence.model.Category{name=c2, pkCategory=120, parent=null, children=null, contentCollection=null}
20:16:19,970 DEBUG ConnectionManager:427 - aggressively releasing JDBC connection
20:16:19,971 DEBUG AbstractFlushingEventListener:134 - processing flush-time cascades
20:16:19,972 DEBUG AbstractFlushingEventListener:177 - dirty checking collections
20:16:19,972 DEBUG AbstractFlushingEventListener:108 - Flushed: 0 insertions, 0 updates, 0 deletions to 1 objects
20:16:19,972 DEBUG AbstractFlushingEventListener:114 - Flushed: 0 (re)creations, 0 updates, 0 removals to 0 collections
20:16:19,973 DEBUG Printer:106 - listing entities:
20:16:19,973 DEBUG Printer:113 - es.blusolutions.blupersistence.model.Category{name=c2, pkCategory=120, parent=null, children=null, contentCollection=null}
20:16:19,973 DEBUG ConnectionManager:427 - aggressively releasing JDBC connection


Top
 Profile  
 
 Post subject: Re: [JTA] UserTransaction doesn't commit or rollback
PostPosted: Fri Nov 19, 2010 8:07 am 
Newbie

Joined: Sun Nov 07, 2010 8:14 am
Posts: 3
I've configured a XAConenctionPool and a XADataSource in glassfish and modify my persistence.properties to use this.
Code:
hibernate.connection.username=root
hibernate.connection.password=
hibernate.connection.datasource=jdbc/database
hibernate.dialect=org.hibernate.dialect.MySQLInnoDBDialect
hibernate.hbm2ddl.auto=none

hibernate.cache.use_second_level_cache=true
hibernate.cache.use_query_cache=false
hibernate.cache.region.jbc2.query.localonly=true
hibernate.cache.region.factory_class=org.hibernate.cache.jbc2.SharedJBossCacheRegionFactory
hibernate.cache.region.jbc2.cfg.shared=treecache.xml

hibernate.transaction.manager_lookup_class=org.hibernate.transaction.SunONETransactionManagerLookup
hibernate.current_session_context_class=jta

And now commit and rollback works, but in some complex sceneario the UserTransaction status is set to STATUS_UNKNOWN after a commit and then the UserTransaction isn't usable anymore. Any idea?


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.