0 Replies Latest reply on Nov 21, 2007 6:50 AM by Breako Beats

    JPA EntityManagerFactory requires access to Transaction Mana

    Breako Beats Newbie

      Hi,
      I am using JBoss Application Server.
      I have a very simple JPA application.
      I define a datasource to use JTA in my persistence.xml

      <persistence-unit name="h-source" transaction-type="JTA">
       <jta-data-source>java:DefaultDS</jta-data-source>
       <properties>
       <property name="hibernate.connection.driver_class" value="org.hsqldb.jdbcDriver"/>
       <property name="hibernate.connection.username" value="sa"/>
       <property name="hibernate.connection.password" value=""/>
       <property name="hibernate.connection.url" value="jdbc:hsqldb:."/>
       <property name="hibernate.hbm2ddl.auto" value="create-drop"/>
       <property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
       </properties>
      </persistence-unit>
      


      I write a simple JSP to instantiate a EntityManagerFactory within a UserTransaction

      <<%
       InitialContext ctx = new InitialContext();
       UserTransaction ut = (UserTransaction)ctx.lookup("UserTransaction");
       ut.begin();
      
       EntityManagerFactory emf =
       Persistence.createEntityManagerFactory("h-source");
      .
      .
      .
      


      I get the following exception

      javax.persistence.PersistenceException: org.hibernate.HibernateException: The chosen transaction strategy requires access to the JTA TransactionManager
       org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:720)
       org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
       javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
      


      I can use JTA in a simple JSP with JDBC.
      My question is can I use an EntityManagerFactory (instantiated by me, not injected) which will use JTA in a simple JSP?


      Or can I only use this type of EntityManagerFactory inside a Session bean?
      This link says that is the case.
      http://www.abcseo.com/tech/java/jboss-ebj-troubleshooting