11 Replies Latest reply on Apr 15, 2004 9:25 PM by Junjie Du

    can not find UserTransaction

    Junjie Du Newbie

      A problem occurred when i configurate connection pool in JBoss.
      My development envrionment is JBoss3.2.3+Mysql4.0.8+Hibernate2.1, i have configurated the datasource, and Hibernate can find the datasource,but there is exception of UserTransaction not found. I wonder whether it is the problem occurred in JBoss or Hibernate configuration, and how can i solve this problem. Thanks very much.


        • 1. Re: can not find UserTransaction
          Adrian Brock Master

          You have configured your bean as BMT?

          Come on show some details, not "IT DOES NOT WORK"

          • 2. Re: can not find UserTransaction
            Junjie Du Newbie

            I have add mysql-connector-java-3.0.11-stable-bin.jar under JBOSS_HOME\server\default\lib and mysql-ds.xml under JBOSS_HOME\server\default\deploy,
            the hibernatecfg.xml is

            <?xml version='1.0' encoding='utf-8'?>
            <!DOCTYPE hibernate-configuration PUBLIC
             "-//Hibernate/Hibernate Configuration DTD 2.0//EN"
            
             "http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
            
            <hibernate-configuration>
            
             <!-- a SessionFactory instance listed as /jndi/name -->
             <session-factory>
            
             <!-- properties -->
             <property name="dialect">net.sf.hibernate.dialect.MySQLDialect</property>
             <property name="connection.driver_class">org.gjt.mm.mysql.Driver</property>
             <property name="connection.provider_class">net.sf.hibernate.connection.DatasourceConnectionProvider</property>
             <property name="connection.datasource">java:/MySqlDS</property>
             <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
             <property name="cache.use_query_cache">true</property>
             <property name="cache.provider_class">net.sf.hibernate.cache.HashtableCacheProvider</property>
            
             <!-- mapping files -->
             <mapping resource="******.hbm.xml"/>
             ......
             </session-factory>
            
            </hibernate-configuration>
            


            • 3. Re: can not find UserTransaction
              Junjie Du Newbie

              It seems i configured my bean as BMT

              • 4. Re: can not find UserTransaction
                Adrian Brock Master

                Seems is ok then. I'll just have to take word for it.

                You'll also have to take word for it that I can't help you without seeing what you doing.

                What makes you think Hibernate configuration has anything to do with BMT
                or user transactions? It is not a part of any j2ee spec.

                Your lack of ability to show relevent information leads me to conclude you have
                no idea what you are doing.

                Regards,
                Adrian

                • 5. Re: can not find UserTransaction
                  Junjie Du Newbie

                  I really want to say thank you first. Let me make the context more clearly.

                  My high level architectural flow :
                  Stateless session bean -> Hibernate -> mysql data source ->database.

                  I congfigured datasource in JBoss, and use the datasource in hibernate to connect to MySQL.

                  I’ve a stateless session bean to handle my data layer operations. Once when I’ve the local-tx-datasource and when I do
                  Session session = HibernateSessionFactory.openSession();
                  ...
                  tx = session.beginTransaction();
                  ...
                  tx.commit();

                  This is style for JDBCTransaction(BMT), so i changed my hibernate.cfg.xml, replace

                  <property name="transaction.factory_class">net.sf.hibernate.transaction.JTATransactionFactory</property>
                  with
                  <property name="transaction.factory_class">net.sf.hibernate.transaction.JDBCTransactionFactory</property>
                  , it is ok when i start JBoss, but when use call the bean to do some database opertion, the JBoss will print out
                  exceptions
                  15:13:21,695 ERROR [JDBCTransaction] Commit failed
                  java.sql.SQLException: You cannot commit during a managed transaction!
                   at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.jdbcCommit(BaseWrapperManagedConnection.java:400)
                   at org.jboss.resource.adapter.jdbc.WrappedConnection.commit(WrappedConnection.java:477)
                   at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:63)
                  ...
                  .
                  The situation is the hibernate connect to database through datasource which is configured in JBoss, whether I can use JDBCTransaction
                  as above? If I can use JDBCTransaction in this situation, what may cause the "Commit failed" error, and what may be the possible solution.
                  If not, must I use CMT, and let container to manager the transaction?

                  I am newbie to both JBoss and Hibernate, I may be not clear with some conceptions related. Thanks!

                  • 6. Re: can not find UserTransaction
                    Adrian Brock Master

                    Whether you are using CMT or BMT,
                    you cannot invoke commit() explicitly.

                    This is handled by the transaction commit not you.

                    If you don't want the connection to be part of the managed transaction
                    you should use

                    <no-tx-datasource>
                    



                    • 7. Re: can not find UserTransaction
                      Adrian Brock Master

                      Or don't start the user transaction in the first place.

                      • 8. Re: can not find UserTransaction
                        Junjie Du Newbie

                        The fact is that, when I configure the hibernate.cfg.xml without using the jndi for datasource, but directly"jdbc:mysql://localhost:3306/***", my application works ok. I want to configure a connection pool in JBoss to tuning the proformance. so i have to use datasource.

                        If i comment off the code,like

                        Session session = HibernateSessionFactory.openSession();
                        ...
                        //tx = session.beginTransaction();
                        ...
                        //tx.commit();

                        There is another problem, i can operate the object made in the transaction only once, i can not modify or delete the object later, which seems as if the transaction is not end, i can not commit any more.

                        • 9. Re: can not find UserTransaction
                          Adrian Brock Master

                          Did you even read my previous comment.
                          no-tx-datasource is exactly like direct jdbc access - except with pooling
                          Any work you do is not part of the JTA tranasction.

                          If you want further help, you need to show how you are using the session
                          and state which of the different configurations of hibernate that you have already posted
                          you are actually using.

                          You also need to post FULL exceptions not "It does not work".
                          Please have a look at the "READ ME FIRST" topic in this forum.

                          I am not going to play ping/pong with you anymore.

                          Regards,
                          Adrian

                          • 10. Re: can not find UserTransaction
                            Adrian Brock Master

                            You might also be interested in this link if you want to learn how it works.

                            http://www.hibernate.org/175.html

                            This forums is for technical question, not hand holding or free consulting.

                            • 11. Re: can not find UserTransaction
                              Junjie Du Newbie

                              I very appreciate your quick feedback. Yesterday, I misundertood the code

                              <no-tx-datasource>
                              . Just now, I tried, replaced
                              <local-tx-datasoure>
                              with
                              <no-tx-datasource>
                              , and my application works ok.

                              Thank you very much.