[jboss-user] [Beginner's Corner] - javax.ejb.EJBException: javax.persistence.TransactionRequiredException

Diego Rivera do-not-reply at jboss.com
Wed Jan 26 10:10:43 EST 2011

Diego Rivera [http://community.jboss.org/people/diego_rivera] created the discussion

"javax.ejb.EJBException: javax.persistence.TransactionRequiredException"

To view the discussion, visit: http://community.jboss.org/message/583343#583343

Hello, everyone!

I'm migrating an application from Glassfish 3.0.1 to JBoss 6.0.0 Final.  To expedite the migration and avoid a rather hefty persistence layer refactor I'm using EclipseLink 2.1.2 as the JPA provider.  Needless to say the application works fine in Glassfish.  Anyway...

The application uses EJB 3.1 in a WAR (Servlet 3.0, JSF 2.0), and JPA 2.0 persistence. I have already defined the DataSources needed (included below).

I've almost got it running in JBoss 6.  But I have a very strange issue regarding transactions not being properly enlisted by the persistence manager (or, at least, that's what it seems).  I keep getting javax.ejb.EJBException: javax.persistence.TransactionRequiredException

Here's the (pseudo) code description-stack-thing:

Initializer.contextInitialized() -> EJB1.init() <Transaction.REQUIRED> -> EJB2.init() <Transaction.REQUIRES_NEW> -> EntityManager.createNamedQuery()

I've confirmed that the code invocation does get as far as the createNamedQuery() call because of trace logging I put in place.  The problem seems to be that EclipseLink is complaining that it can't find a transaction which should obviously be there.

I've added the "eclipselink.transaction.join-existing" configuration to EclipseLink, and produced no change.  I've also turned up the logging in EL in an attempt to determine where the problem is.  Eclipselink is finding the correct data source (I can see that from its logs) - it's joining the transaction it seems to be having trouble with.

This is the datasource declaration in question:
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <datasources>
>         <local-tx-datasource>
>                 <jndi-name>MyDS</jndi-name>
>                 <connection-url>jdbc:postgresql://localhost:5432/mydb</connection-url>
>                 <driver-class>org.postgresql.Driver</driver-class>
>                 <user-name>mydb</user-name>
>                 <password>mydb</password>
>                 <check-valid-connection-sql>select 1</check-valid-connection-sql>
>                 <metadata>
>                         <type-mapping>PostgreSQL 8.0</type-mapping>
>                 </metadata>
>                 <min-pool-size>8</min-pool-size>
>                 <max-pool-size>32</max-pool-size>
>                 <idle-timeout-minutes>30</idle-timeout-minutes>
>                 <prefill>true</prefill>
>         </local-tx-datasource>
> </datasources>
The JDBC driver jar is in the right place, the datasource is shown as active in the admin console, etc.

I've not tested using an XA datasource because I'd just as soon avoid the overhead if I can (since I don't need it).  This is my persistence.xml:
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence xmlns:xsi=" http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance" version="2.0"
>           xmlns=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence" xmlns:jpa=" http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
>           xsi:schemaLocation=" http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence  http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
>           <persistence-unit name="Persistence Core">
>                     <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
>                     <jta-data-source>java:/MyDS</jta-data-source>
>                     <shared-cache-mode>NONE</shared-cache-mode>
>                     <properties>
>                <property name="eclipselink.logging.level" value="ALL"/> 
>                               <property name="eclipselink.target-database" value="PostgreSQL"/>
>                               <property name="eclipselink.weaving.changetracking" value="false"/>
>                <property name="eclipselink.transaction.join-existing" value="true"/>
>             </properties>
>           </persistence-unit>
> </persistence>

Maybe I'm missing something in jboss-web.xml? This is the one I'm using...

> <?xml version="1.0" encoding="UTF-8"?>  
> <!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 3.0//EN" " http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
> <jboss-web>
>           <context-root>/</context-root>
> </jboss-web>

As you can see, no funkyness there... maybe that's the problem?

The other problem I was having was that originally I was using a @Startup @Singleton bean with a @PostConstruct method, and was getting exceptions regarding @PostConstruct being called on a newly created bean. Thus, I switched to the WebListener-based startup model that I'm currently using (which should work just the same anyway).


Reply to this message by going to Community

Start a new discussion in Beginner's Corner at Community

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/jboss-user/attachments/20110126/c22648fd/attachment.html 

More information about the jboss-user mailing list