<!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;">
    EJB3/JPA 2.0 support for AS-7
</h3>
<span style="margin-bottom: 10px;">
    created by <a href="http://community.jboss.org/people/smarlow%40redhat.com">Scott Marlow</a> in <i>JBoss AS7 Development</i> - <a href="http://community.jboss.org/docs/DOC-16271">View the full document</a>
</span>
<hr style="margin: 20px 0; border: none; background-color: #dadada; height: 1px;">

<div class="jive-rendered-content"><p style="margin-bottom: 0in;">This is about how the AS-7 JPA layer and related concerns. </p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p><ol><li><p style="margin-bottom: 0in;">Container-managed persistence &#160;&#160;&#160;&#160;&#160;context</p><ol><li><p style="margin-bottom: 0in;">Transaction scope (JPA 7.6.1)</p><ol><li><p style="margin-bottom: 0in;">Transaction active invocation</p><ol><li><p style="margin-bottom: 0in;">Persistence context is created &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;if none already associated with transaction</p></li><li><p style="margin-bottom: 0in;">Created persistence context &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ends when transaction ends</p></li><li><p style="margin-bottom: 0in;">An extended persistence context &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;can also be used, which survives when transaction ends.</p></li></ol> </li><li><p style="margin-bottom: 0in;">No transaction invocation</p><ol><li><p style="margin-bottom: 0in;">Loaded entities are detached at &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;end of method call.</p></li></ol> </li></ol> </li><li><p style="margin-bottom: 0in;">Extended scope (JPA 7.6.2)</p><ol><li><p style="margin-bottom: 0in;">Only supported for stateful &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;session beans.</p></li><li><p style="margin-bottom: 0in;">Entity modifications can be made &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;outside of a transaction and are applied on the next joined &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;transaction (anywhere on the cluster).</p></li><li><p style="margin-bottom: 0in;">Extended persistence context &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(XPC) is created when stateful bean that depends on a XPC is &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;created.</p></li><li><p style="margin-bottom: 0in;">XPC is closed when dependent &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;session bean(s) are closed (via @remove method).</p></li><li><p style="margin-bottom: 0in;">Inheritance</p><ol><li><p style="margin-bottom: 0in;">Stateful beans that create &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;other (local) stateful beans, share the same XPC.</p></li></ol> </li></ol> </li><li><p style="margin-bottom: 0in;">Persistence context propagation &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;(JPA 7.6.3)</p><ol><li><p style="margin-bottom: 0in;">A persistence context will be &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;propagated to multiple entity managers (instances) within the same &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;local transaction.</p></li><li><p style="margin-bottom: 0in;">Remote invocations do not &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;propagate the persistence context.</p></li></ol> </li><li><p style="margin-bottom: 0in;">Persistence context propagation &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;requirements for component invocations (JPA 7.6.3.1)</p><ol><li><p style="margin-bottom: 0in;">no propagation if component is &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;invoked without a JTA transaction or without the JTA transaction &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;propagating:</p><ol><li><p style="margin-bottom: 0in;">Transaction scoped entity &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;manager used within the invoked component, will create a new &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;persistence context.</p></li><li><p style="margin-bottom: 0in;">Extended scoped entity manager &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;used within the invoked component, will use the XPC already bound &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;to the (invoked stateful) bean.</p></li><li><p style="margin-bottom: 0in;">If the entity manager is &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;invoked within a JTA transaction, the persistence context is &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;bound to the JTA transaction.</p></li></ol> </li><li><p style="margin-bottom: 0in;">If a component is invoked and &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;the JTA transaction is propagated into the component:</p><ol><li><p style="margin-bottom: 0in;">If (SFSB) component has a XPC &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;and the transaction already has a different persistence context &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;associated with it, an EJBException is thrown by the container.</p></li><li><p style="margin-bottom: 0in;">If a persistence context is &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;bound to the JTA transaction, it is propagated into any entity &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;managers used in the invocation.</p></li></ol> </li></ol> </li></ol> </li><li><p style="margin-bottom: 0in;">Container requirements review</p><ol><li><p style="margin-bottom: 0in;">Application-managed persistence &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;context (JPA 7.8.1)</p><ol><li><p style="margin-bottom: 0in;">Container needs to inject entity &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;manager factory into jndi for application use.</p></li><li><p style="margin-bottom: 0in;">Must use &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PersistenceProvider.createContainerEntityManagerFactory method for &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;3<sup>rd</sup> party support.&#160; Internal APIs are fine for our &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;persistence provider.</p></li><li><p style="margin-bottom: 0in;">Must use &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EntityManagerFactory.close method to close the entity manager &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;factory prior to shutdown (again for 3<sup>rd</sup> party &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;support).</p></li></ol> </li><li><p style="margin-bottom: 0in;">Container-managed persistence &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;context (JPA 7.9.1)</p><ol><li><p style="margin-bottom: 0in;">For 3<sup>rd</sup> party &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;support, use EntityManagerFactory.createEntityManager .&#160; Consider &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;using&#160; for our persistence provider as well.</p></li><li><p style="margin-bottom: 0in;">May pass (<code class="western"><span style="font-size: 10pt;"><a class="jive-link-external-small" href="http://download.oracle.com/javaee/6/api/javax/persistence/PersistenceProperty.html">PersistenceProperty</a>[]</span></code>) &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PersistenceContext.properties to &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EntityManagerFactory.createEntityManager(Map map) .</p></li><li><p style="margin-bottom: 0in;">Container EM wrapper could &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;implement some EntityManager.unwrap(Class&lt;T&gt; cls) calls but &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;should default to underlying EM for unhandled classes.</p></li></ol> </li></ol> </li><li><p style="margin-bottom: 0in;">Deployment</p><ol><li><p style="margin-bottom: 0in;">Extract persistence metadata from &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;persistence.xml</p></li><li><p style="margin-bottom: 0in;">Determine the &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PersistenceProvider&#160; classname for each persistence unit (PU).&#160; The &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;default class is currently org.hibernate.ejb.HibernatePersistence.</p></li><li><p style="margin-bottom: 0in;">Invoke the &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PersistenceProvider.createContainerEntityManagerFactory(PersistenceUnitInfo, &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;Map) to create the EMF that will be used to create all &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;EntityManager's for the PU.&#160; The properties read from the PU are &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;passed as the second parameter.</p></li><li><p style="margin-bottom: 0in;">Also pass the &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&ldquo;javax.persistence.validation.factory &#8221; property if validation &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;mode is not set to NONE.&#160; The validator factory value appears to be &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;org.hibernate.validator.engine.ValidatorFactoryImpl.&#160; Consult &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;ValidatorFactoryProvider which is currently used to bootstrap the &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;validator factory in AS6.</p></li><li><p style="margin-bottom: 0in;">The PU classes shouldn't be &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;loaded until after the EMF is created.</p></li><li><p style="margin-bottom: 0in;">The EntityManagerFactory is &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;closed at undeploy time, which also closes all EntityManager's &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;opened by each factory.</p></li><li><p style="margin-bottom: 0in;">Switchboard changes for PU + &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;PC???</p></li></ol> </li><li><p style="margin-bottom: 0in;">Clustering</p><ol><li><p style="margin-bottom: 0in;">Determine impact on &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a class="" href="http://community.jboss.org/docs/DOC-13822">http://community.jboss.org/wiki/OptimizingentityandXPCreplication</a> which may need to be tweaked for clustering other persistence &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;providers.&#160; Judging by the jira status, this optimization is not in &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;place yet (although the Hibernate persistence provider jira &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;HHH-2762 is done).</p></li><li><p style="margin-bottom: 0in;">Determine impact on &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;<a class="" href="http://community.jboss.org/docs/DOC-9565">http://community.jboss.org/wiki/DevEJB3NewSFSBCache</a> (consider support for other persistence providers).</p></li></ol> </li><li><p style="margin-bottom: 0in;">Weld integration &#160;&#160;&#160;&#160;&#160;(JpaInjectionServices implementation is wired in at boot time)</p><p style="min-height: 8pt; height: 8pt; padding: 0px;">&#160;</p></li></ol></div>

<div style="background-color: #f4f4f4; padding: 10px; margin-top: 20px;">
    <p style="margin: 0;">Comment by <a href="http://community.jboss.org/docs/DOC-16271">going to Community</a></p>

        <p style="margin: 0;">Create a new document in JBoss AS7 Development at <a href="http://community.jboss.org/choose-container!input.jspa?contentType=102&containerType=14&container=2225">Community</a></p>
</div></td>
                        </tr>
                    </tbody>
                </table>


                </td>
            </tr>
        </tbody>
    </table>

</div>

</body>
</html>