<!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;">&#160;</p><p>I'm migrating an application from Glassfish 3.0.1 to JBoss 6.0.0 Final.&#160; To expedite the migration and avoid a rather hefty persistence layer refactor I'm using EclipseLink 2.1.2 as the JPA provider.&#160; Needless to say the application works fine in Glassfish.&#160; Anyway...</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&#160;</p><p>I've almost got it running in JBoss 6.&#160; 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).&#160; I keep getting javax.ejb.EJBException: javax.persistence.TransactionRequiredException</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Here's the (pseudo) code description-stack-thing:</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>Initializer.contextInitialized() -&gt; EJB1.init() &lt;Transaction.REQUIRED&gt; -&gt; EJB2.init() &lt;Transaction.REQUIRES_NEW&gt; -&gt; EntityManager.createNamedQuery()</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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.&#160; 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;">&#160;</p><p>I've added the "eclipselink.transaction.join-existing" configuration to EclipseLink, and produced no change.&#160; I've also turned up the logging in EL in an attempt to determine where the problem is.&#160; 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;">&#160;</p><p>This is the datasource declaration in question:</p><blockquote class="jive-quote"><p>&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;</p><p>&lt;datasources&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;local-tx-datasource&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;jndi-name&gt;MyDS&lt;/jndi-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;connection-url&gt;jdbc:postgresql://localhost:5432/mydb&lt;/connection-url&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;driver-class&gt;org.postgresql.Driver&lt;/driver-class&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;user-name&gt;mydb&lt;/user-name&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;password&gt;mydb&lt;/password&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;check-valid-connection-sql&gt;select 1&lt;/check-valid-connection-sql&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;metadata&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;type-mapping&gt;PostgreSQL 8.0&lt;/type-mapping&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/metadata&gt;</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;min-pool-size&gt;8&lt;/min-pool-size&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;max-pool-size&gt;32&lt;/max-pool-size&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;idle-timeout-minutes&gt;30&lt;/idle-timeout-minutes&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;prefill&gt;true&lt;/prefill&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/local-tx-datasource&gt;</p><p>&lt;/datasources&gt;</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;">&#160;</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).&#160; This is my persistence.xml:</p><blockquote class="jive-quote"><p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;</p><p><span>&lt;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>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;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>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;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>"&gt;</span></p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&lt;persistence-unit name="Persistence Core"&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;provider&gt;org.eclipse.persistence.jpa.PersistenceProvider&lt;/provider&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;jta-data-source&gt;java:/MyDS&lt;/jta-data-source&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;shared-cache-mode&gt;NONE&lt;/shared-cache-mode&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;properties&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="eclipselink.logging.level" value="ALL"/&gt; </p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;property name="eclipselink.target-database" value="PostgreSQL"/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&lt;property name="eclipselink.weaving.changetracking" value="false"/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;!-- BEGIN PROPERTIES NEEDED FOR JBOSS COMPATIBILITY --&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;property name="eclipselink.transaction.join-existing" value="true"/&gt;</p><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &lt;/properties&gt;</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&lt;/persistence-unit&gt;</p><p>&lt;/persistence&gt;</p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&#160;</p><blockquote class="jive-quote"><p>&lt;?xml version="1.0" encoding="UTF-8"?&gt;&#160; </p><p><span>&lt;!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>"&gt;</span></p><p>&lt;jboss-web&gt;</p><p>&#160;&#160;&#160;&#160; &#160;&#160;&#160;&#160;&#160;&lt;context-root&gt;/&lt;/context-root&gt;</p><p>&lt;/jboss-web&gt;</p></blockquote><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><p>As you can see, no funkyness there... maybe that's the problem?</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</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;">&#160;</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>