users@glassfish.java.net

Re: embedded ejb container - JTA and entity managers

From: Mitesh Meswani <mitesh.meswani_at_oracle.com>
Date: Thu, 03 Mar 2011 16:07:30 -0800

For EclipseLink to be aware of GlassFish TransactionManager, you need
to specify <property name="eclipselink.target-server" value="SunAS9"/> .
Without this property I do not think your use case would have worked in
3.0.1 either.

Thanks,
Mitesh
On 3/3/2011 11:36 AM, Phillip Ross wrote:
> Here's an inline, slightly abbreviated version of my persistence.xml
>
> <?xml version="1.0" encoding="UTF-8"?>
> <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/persistence_2_0.xsd"
> version="2.0">
>
> <persistence-unit name="default" transaction-type="JTA">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
> <jta-data-source>jdbc/test_ds</jta-data-source>
> <class>TestEntity</class>
> <properties>
> <property name="eclipselink.logging.level" value="SEVERE"/>
> </properties>
> </persistence-unit>
> </persistence>
>
> The real one has a different datasource name and lots more, real class
> names, but this one illustrates the pu name and tx type I'm attempting
> to use.
>
> Another interesting datapoint, I added some code to interrogate the
> entity manager and it seems to not know the server platform or claim
> to support JTA. Code looks like this:
> Object entityManagerDelegateObject = entityManager.getDelegate();
> logger.debug("Retrieved a delegate object of type {}",
> entityManagerDelegateObject.getClass().getName());
> if (entityManagerDelegateObject instanceof EntityManagerImpl) {
> EntityManagerImpl entityManagerImpl =
> (EntityManagerImpl)entityManager.getDelegate();
> Session session = entityManagerImpl.getSession();
> ServerPlatform serverPlatform = session.getServerPlatform();
> logger.debug("server platform: {}",
> serverPlatform.getServerNameAndVersion());
> logger.debug("jta enabled: {}",
> serverPlatform.isJTAEnabled());
> }
>
> And the output from this looks like this:
> - Retrieved a delegate object of type
> org.eclipse.persistence.internal.jpa.EntityManagerImpl
> - server platform: null
> - jta enabled: false
>
> But placing the same code inside a stateless EJB produces this output:
> - server platform: unknown
> - jta enabled: true
>
> I dont really know if this has anything to do with anything, but
> thought it was interesting.
>
>
> On Thu, Mar 3, 2011 at 1:33 PM, Mitesh Meswani
> <mitesh.meswani_at_oracle.com <mailto:mitesh.meswani_at_oracle.com>> wrote:
>
> On 3/3/2011 10:30 AM, Phillip Ross wrote:
>
> at
> org.eclipse.persistence.internal.jpa.transaction.EntityTransactionWrapper.checkForTransaction(EntityTransactionWrapper.java:50)
>
> Use of EntityTransactionWrapper implies that you are not using a
> JTA pu. Check your persistence.xml to make sure that it is a JTA pu.
>
> -Mitesh
>
> at
> org.eclipse.persistence.internal.jpa.EntityManagerImpl.checkForTransaction(EntityManagerImpl.java:1666)
>
>
>