0 Replies Latest reply on Dec 16, 2008 7:23 AM by gz ziyu

    javax.naming.NameNotFoundException: TransactionManager not

    gz ziyu Newbie

      hi,
      I want to use JTA in Hibernate app,when runing the below code ,
      UserTransaction ut = (UserTransaction)new InitialContext().lookup("java:comp/UserTransaction");

      caused error the below:
      at cc.ziyu.hibernate.trainee.test.LoadLecturerJTA.main(Unknown Source)
      Caused by: org.hibernate.HibernateException: Could not locate TransactionManager
      at org.hibernate.transaction.JNDITransactionManagerLookup.getTransactionManager(JNDITransactionManagerLookup.java:26)
      at org.hibernate.impl.SessionFactoryImpl.(SessionFactoryImpl.java:325)
      at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
      ... 2 more
      Caused by: javax.naming.NameNotFoundException: TransactionManager not bound
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:529)
      at org.jnp.server.NamingServer.getBinding(NamingServer.java:537)
      at org.jnp.server.NamingServer.getObject(NamingServer.java:543)
      at org.jnp.server.NamingServer.lookup(NamingServer.java:296)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      .....

      hibernate.cfg.xml:
      <?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">

      <hibernate-configuration>
      <session-factory name="ziyu">

      com.mysql.jdbc.Driver


      <!-- -->

      java:/chap13




      org.hibernate.dialect.MySQLDialect



      <!-- -->

      org.hibernate.transaction.JTATransactionFactory



      org.hibernate.transaction.JBossTransactionManagerLookup


      <!-- -->

      java:comp/UserTransaction




      true
      true
      <!-- -->



      </session-factory>
      </hibernate-configuration>

      mysql-ds.xml:

      <local-tx-datasource>
      <jndi-name>chap13</jndi-name>
      <connection-url>jdbc:mysql://localhost:3306/chap13</connection-url>
      <driver-class>com.mysql.jdbc.Driver</driver-class>
      <user-name>root</user-name>
      rootadmin
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLExceptionSorter</exception-sorter-class-name>
      <!-- should only be used on drivers after 3.22.1 with "ping" support
      <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>
      -->
      <!-- sql to call when connection is created
      <new-connection-sql>some arbitrary sql</new-connection-sql>
      -->
      <!-- sql to call on an existing pooled connection when it is obtained from pool - MySQLValidConnectionChecker is preferred for newer drivers
      <check-valid-connection-sql>some arbitrary sql</check-valid-connection-sql>
      -->

      <!-- corresponding type-mapping in the standardjbosscmp-jdbc.xml (optional) -->

      <type-mapping>mySQL</type-mapping>

      </local-tx-datasource>


      why caused these error?