-->
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.  [ 6 posts ] 
Author Message
 Post subject: Transaction problem with JPA in Jboss
PostPosted: Sun Feb 04, 2007 6:41 am 
Newbie

Joined: Tue Jan 30, 2007 5:58 pm
Posts: 14
Hi,

I use Jboss 4.0.5 and Hibernate with JPA and I have this exception when I want to commit the transaction after a persist call of a POJO in a stateless session bean:

Exception: java.lang.IllegalStateException: JTA EntityManager cannot access a transactions

EntityTransaction tx = em.getTransaction();
tx.begin();
em.persist(actor);
tx.commit();
em.close();

Thanks for your help.

11:21:43,052 ERROR [STDERR] java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
11:21:43,052 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316)

Ejb-jar.xml:
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
<assembly-descriptor>
<container-transaction>
<method>
<ejb-name>CatalogManagerBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Supports</trans-attribute>
</container-transaction>
</assembly-descriptor>


Persistence.xml
<properties>
<property name="hibernate.archive.autodetection"
value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/dvdstore" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password"
value="system" />
<property name="hibernate.transaction.factory_class"
value="org.hibernate.ejb.transaction.JoinableCMTTransactionFactory" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
</properties>

Full Exception Trace:

11:21:39,717 INFO [Version] Hibernate EntityManager 3.2.0.GA
11:21:39,747 INFO [Version] Hibernate Annotations 3.2.0.GA
11:21:39,767 INFO [Environment] Hibernate 3.2.0.ga
11:21:39,777 INFO [Environment] hibernate.properties not found
11:21:39,777 INFO [Environment] Bytecode provider name : cglib
11:21:39,787 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
11:21:40,087 WARN [Ejb3Configuration] Overriding hibernate.transaction.factory_class is dangerous, this might break the EJB3 specification implementation
11:21:41,139 INFO [DriverManagerConnectionProvider] Using Hibernate built-in connection pool (not for production use!)
11:21:41,139 INFO [DriverManagerConnectionProvider] Hibernate connection pool size: 20
11:21:41,139 INFO [DriverManagerConnectionProvider] autocommit mode: true
11:21:41,139 INFO [DriverManagerConnectionProvider] using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://localhost:3306/dvdstore
11:21:41,139 INFO [DriverManagerConnectionProvider] connection properties: {user=root, password=system, autocommit=true, release_mode=auto}
11:21:42,020 INFO [SettingsFactory] RDBMS: MySQL, version: 4.1.21-community-nt
11:21:42,020 INFO [SettingsFactory] JDBC driver: MySQL-AB JDBC Driver, version: mysql-connector-java-5.0.4 ( $Date: 2006-10-19 17:47:48 +0200 (Thu, 19 Oct 2006) $, $Revision: 5908 $ )
11:21:42,060 INFO [Dialect] Using dialect: org.hibernate.dialect.MySQLDialect
11:21:42,070 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.ejb.transaction.JoinableCMTTransactionFactory
11:21:42,080 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
11:21:42,080 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
11:21:42,080 INFO [SettingsFactory] Automatic flush during beforeCompletion(): disabled
11:21:42,080 INFO [SettingsFactory] Automatic session close at end of transaction: disabled
11:21:42,080 INFO [SettingsFactory] JDBC batch size: 15
11:21:42,080 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
11:21:42,090 INFO [SettingsFactory] Scrollable result sets: enabled
11:21:42,090 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
11:21:42,090 INFO [SettingsFactory] Connection release mode: auto
11:21:42,090 INFO [SettingsFactory] Maximum outer join fetch depth: 2
11:21:42,090 INFO [SettingsFactory] Default batch fetch size: 1
11:21:42,090 INFO [SettingsFactory] Generate SQL with comments: disabled
11:21:42,090 INFO [SettingsFactory] Order SQL updates by primary key: disabled
11:21:42,090 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
11:21:42,100 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
11:21:42,100 INFO [SettingsFactory] Query language substitutions: {}
11:21:42,100 INFO [SettingsFactory] JPA-QL strict compliance: enabled
11:21:42,100 INFO [SettingsFactory] Second-level cache: enabled
11:21:42,100 INFO [SettingsFactory] Query cache: disabled
11:21:42,100 INFO [SettingsFactory] Cache provider: org.hibernate.cache.NoCacheProvider
11:21:42,100 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
11:21:42,100 INFO [SettingsFactory] Structured second-level cache entries: disabled
11:21:42,110 INFO [SettingsFactory] Echoing all SQL to stdout
11:21:42,110 INFO [SettingsFactory] Statistics: disabled
11:21:42,110 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
11:21:42,110 INFO [SettingsFactory] Default entity-mode: pojo
11:21:42,180 INFO [SessionFactoryImpl] building session factory
11:21:42,931 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
11:21:42,941 INFO [NamingHelper] JNDI InitialContext properties:{}
11:21:43,052 ERROR [STDERR] java.lang.IllegalStateException: JTA EntityManager cannot access a transactions
11:21:43,052 ERROR [STDERR] at org.hibernate.ejb.AbstractEntityManagerImpl.getTransaction(AbstractEntityManagerImpl.java:316)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 05, 2007 11:55 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I suspect you use he EM in JTA transaction-type, hence you cannot use the getTransaction() API, but you don't show enough of your persistence.xml

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 06, 2007 5:02 am 
Newbie

Joined: Tue Jan 30, 2007 5:58 pm
Posts: 14
This is my persistence.xml file:

<persistence 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/ ... ce_1_0.xsd"
version="1.0">
<persistence-unit name="dvdstorePU" transaction-type="JTA">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<property name="hibernate.archive.autodetection"
value="class, hbm" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<property name="hibernate.dialect"
value="org.hibernate.dialect.MySQLDialect" />
<property name="hibernate.connection.driver_class"
value="com.mysql.jdbc.Driver" />
<property name="hibernate.connection.url"
value="jdbc:mysql://localhost:3306/dvdstore" />
<property name="hibernate.connection.username" value="root" />
<property name="hibernate.connection.password"
value="system" />
<property name="hibernate.transaction.manager_lookup_class"
value="org.hibernate.transaction.JBossTransactionManagerLookup" />
</properties>
</persistence-unit>
</persistence>

I've changed the ejb-jar.xml: I use Bean because I use BMT inside the ejb session code.
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
</session>
</enterprise-beans>

In the ejb session bean:
Actor actor = new Actor();
actor.setFirstname(firstname);
actor.setName(name);

EntityManagerFactory emf = Persistence.createEntityManagerFactory("dvdstorePU");

EntityManager em = emf.createEntityManager();
UserTransaction tx = (UserTransaction) new InitialContext().lookup("UserTransaction");
tx.begin();
em.persist(actor);
tx.commit();
em.close();

Thanks for any help which could solve my problem: my POJO class is not stored in the database, and I have no exception.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 8:23 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Look the spec or Hibernate EM ref doc for em.joinTransaction()

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 07, 2007 8:24 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
BTW I don't understand people using BMT :-)

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 08, 2007 8:39 am 
Newbie

Joined: Tue Jan 30, 2007 5:58 pm
Posts: 14
Thanks very much for your answer, it works perfectly with the joinTransaction method.

EntityManagerFactory emf = Persistence.createEntityManagerFactory("dvdstorePU");
EntityManager em = emf.createEntityManager();
tx = (UserTransaction) new InitialContext().lookup("UserTransaction");
tx.begin();
em.joinTransaction();
em.persist(actor);
tx.commit();
em.close();


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