<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body link="#355491" alink="#4262a1" vlink="#355491" style="background: #e2e2e2; margin: 0; padding: 20px;">
<div>
        <table cellpadding="0" bgcolor="#FFFFFF" border="0" cellspacing="0" style="border: 1px solid #dadada; margin-bottom: 30px; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                <tbody>
                        <tr>
                                <td>
                                        <table border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" style="border: solid 2px #ccc; background: #dadada; width: 100%; -moz-border-radius: 6px; -webkit-border-radius: 6px;">
                                                <tbody>
                                                        <tr>
                                                                <td bgcolor="#000000" valign="middle" height="58px" style="border-bottom: 1px solid #ccc; padding: 20px; -moz-border-radius-topleft: 3px; -moz-border-radius-topright: 3px; -webkit-border-top-right-radius: 5px; -webkit-border-top-left-radius: 5px;">
                                                                        <h1 style="color: #333333; font: bold 22px Arial, Helvetica, sans-serif; margin: 0; display: block !important;">
                                                                        <!-- To have a header image/logo replace the name below with your img tag -->
                                                                        <!-- Email clients will render the images when the message is read so any image -->
                                                                        <!-- must be made available on a public server, so that all recipients can load the image. -->
                                                                        <a href="http://community.jboss.org/index.jspa" style="text-decoration: none; color: #E1E1E1">JBoss Community</a></h1>
                                                                </td>
                                                        </tr>
                                                        <tr>
                                                                <td bgcolor="#FFFFFF" style="font: normal 12px Arial, Helvetica, sans-serif; color:#333333; padding: 20px; -moz-border-radius-bottomleft: 4px; -moz-border-radius-bottomright: 4px; -webkit-border-bottom-right-radius: 5px; -webkit-border-bottom-left-radius: 5px;"><h3 style="margin: 10px 0 5px; font-size: 17px; font-weight: normal;">
javax.ejb.EJBException: javax.persistence.TransactionRequiredException
</h3>
<span style="margin-bottom: 10px;">
created by <a href="http://community.jboss.org/people/diego_rivera">Diego Rivera</a> in <i>Beginner's Corner</i> - <a href="http://community.jboss.org/message/583343#583343">View the full discussion</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">
<div class="jive-rendered-content"><p>Hello, everyone!</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Here's the (pseudo) code description-stack-thing:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Initializer.contextInitialized() -> EJB1.init() <Transaction.REQUIRED> -> EJB2.init() <Transaction.REQUIRES_NEW> -> EntityManager.createNamedQuery()</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>This is the datasource declaration in question:</p><blockquote class="jive-quote"><p><?xml version="1.0" encoding="UTF-8" standalone="yes"?></p><p><datasources></p><p>        <local-tx-datasource></p><p>                <jndi-name>MyDS</jndi-name></p><p>                <connection-url>jdbc:postgresql://localhost:5432/mydb</connection-url></p><p>                <driver-class>org.postgresql.Driver</driver-class></p><p>                <user-name>mydb</user-name></p><p>                <password>mydb</password></p><p>                <check-valid-connection-sql>select 1</check-valid-connection-sql></p><p>                <metadata></p><p>                        <type-mapping>PostgreSQL 8.0</type-mapping></p><p>                </metadata></p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>                <min-pool-size>8</min-pool-size></p><p>                <max-pool-size>32</max-pool-size></p><p>                <idle-timeout-minutes>30</idle-timeout-minutes></p><p>                <prefill>true</prefill></p><p>        </local-tx-datasource></p><p></datasources></p></blockquote><p>The JDBC driver jar is in the right place, the datasource is shown as active in the admin console, etc.</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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:</p><blockquote class="jive-quote"><p><?xml version="1.0" encoding="UTF-8"?></p><p><span><persistence xmlns:xsi="</span><a class="jive-link-external-small" href="http://www.w3.org/2001/XMLSchema-instance" target="_blank">http://www.w3.org/2001/XMLSchema-instance</a><span>" version="2.0"</span></p><p><span>          xmlns="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a><span>" xmlns:jpa="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" target="_blank">http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd</a><span>"</span></p><p><span>          xsi:schemaLocation="</span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence" target="_blank">http://java.sun.com/xml/ns/persistence</a><span> </span><a class="jive-link-external-small" href="http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" target="_blank">http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd</a><span>"></span></p><p>          <persistence-unit name="Persistence Core"></p><p>                    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider></p><p>                    <jta-data-source>java:/MyDS</jta-data-source></p><p>                    <shared-cache-mode>NONE</shared-cache-mode></p><p>                    <properties></p><p>               <property name="eclipselink.logging.level" value="ALL"/> </p><p>                              <property name="eclipselink.target-database" value="PostgreSQL"/></p><p>                              <property name="eclipselink.weaving.changetracking" value="false"/></p><p>               <!-- BEGIN PROPERTIES NEEDED FOR JBOSS COMPATIBILITY --></p><p>               <property name="eclipselink.transaction.join-existing" value="true"/></p><p>            </properties></p><p>          </persistence-unit></p><p></persistence></p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Maybe I'm missing something in jboss-web.xml? This is the one I'm using...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><blockquote class="jive-quote"><p><?xml version="1.0" encoding="UTF-8"?>  </p><p><span><!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 3.0//EN" "</span><a class="jive-link-external-small" href="http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd" target="_blank">http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd</a><span>"></span></p><p><jboss-web></p><p>          <context-root>/</context-root></p><p></jboss-web></p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>As you can see, no funkyness there... maybe that's the problem?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>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).</p><p style="min-height: 8pt; height: 8pt; padding: 0px;"> </p><p>Thanks!</p></div>
<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
<p style="margin: 0;">Reply to this message by <a href="http://community.jboss.org/message/583343#583343">going to Community</a></p>
        <p style="margin: 0;">Start a new discussion in Beginner's Corner at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=1&containerType=14&container=2075">Community</a></p>
</div></td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>