Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » javax.persistence.TransactionRequiredException thrown on EntityManager.flush
javax.persistence.TransactionRequiredException thrown on EntityManager.flush [message #376337] Fri, 11 July 2008 14:52 Go to next message
Brett Bergquist is currently offline Brett BergquistFriend
Messages: 31
Registered: July 2009
Member
I just downloaded and tried to give EclipseLink a spin in replacing
Toplink Essentials in a container managed JPA environment. I am finding
that EntityManager.flush is throwing
javax.persistence.TransactionRequiredException.

I have a little test case with a stateless session bean:

package bean;
import javax.ejb.Local;
@Local
public interface SomeLocal {
void testFlush();
}

and implementation:

package bean;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless
public class SomeBean implements SomeLocal {
@PersistenceContext
private EntityManager em;
public void testFlush() {
SomeEntity se = new SomeEntity();
em.persist(se);
em.flush();
}
}

My persistence.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="1.0" 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_1_0.xsd">
<persistence-unit name="eclipselinktest-ejbPU" transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >
<jta-data-source>jdbc/sample</jta-data-source>
<properties>
<property name="eclipselink.ddl-generation"
value="drop-and-create-tables"/>
</properties>
</persistence-unit>
</persistence>


This is deployed in Glassfish and when I invoke the "testFlush" method
from a client, the exception is thrown. The EntityManager should be
injected as a container managed transaction scoped EntityManager. The
session bean specifies no transaction annotations so all methods should
be invoked in a new transaction.

So what gives?
Re: javax.persistence.TransactionRequiredException thrown on EntityManager.flush [message #376338 is a reply to message #376337] Fri, 11 July 2008 15:11 Go to previous message
Brett Bergquist is currently offline Brett BergquistFriend
Messages: 31
Registered: July 2009
Member
Did some searching and found I needed to add:

<property name="eclipselink.target-server" value="SunAS9"/>

to my persistence.xml for container based transactions to work.

Brett Bergquist wrote:
> I just downloaded and tried to give EclipseLink a spin in replacing
> Toplink Essentials in a container managed JPA environment. I am finding
> that EntityManager.flush is throwing
> javax.persistence.TransactionRequiredException.
>
> I have a little test case with a stateless session bean:
>
> package bean;
> import javax.ejb.Local;
> @Local
> public interface SomeLocal {
> void testFlush();
> }
>
> and implementation:
>
> package bean;
> import javax.ejb.Stateless;
> import javax.ejb.TransactionAttribute;
> import javax.ejb.TransactionAttributeType;
> import javax.persistence.EntityManager;
> import javax.persistence.PersistenceContext;
> @Stateless
> public class SomeBean implements SomeLocal {
> @PersistenceContext
> private EntityManager em;
> public void testFlush() {
> SomeEntity se = new SomeEntity();
> em.persist(se);
> em.flush();
> }
> }
>
> My persistence.xml is:
> <?xml version="1.0" encoding="UTF-8"?>
> <persistence version="1.0"
> 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_1_0.xsd">
> <persistence-unit name="eclipselinktest-ejbPU" transaction-type="JTA">
> <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider >
> <jta-data-source>jdbc/sample</jta-data-source>
> <properties>
> <property name="eclipselink.ddl-generation"
> value="drop-and-create-tables"/>
> </properties>
> </persistence-unit>
> </persistence>
>
>
> This is deployed in Glassfish and when I invoke the "testFlush" method
> from a client, the exception is thrown. The EntityManager should be
> injected as a container managed transaction scoped EntityManager. The
> session bean specifies no transaction annotations so all methods should
> be invoked in a new transaction.
>
> So what gives?
>
>
>
>
Previous Topic:EclipseLink 1.0 Released
Next Topic:JPA vs. Native
Goto Forum:
  


Current Time: Fri Apr 26 06:28:04 GMT 2024

Powered by FUDForum. Page generated in 0.02847 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top