[jboss-user] [EJB 3.0] - tx attributte - supports doesn't work as expected
adamzrk
do-not-reply at jboss.com
Sun Jun 3 09:35:19 EDT 2007
Hi
I've got an EJB:
| @Stateless
| @TransactionAttribute(TransactionAttributeType.SUPPORTS)
| public class AirportDaoBean implements AirportDaoLocal, AirportDaoRemote {
|
| @PersistenceContext
| private EntityManager manager;
|
| @Override
| public void createAirport(Airport airport) {
| manager.persist(airport);
| }
|
| @Override
| public Airport getAirportById(int id) {
| return manager.find(Airport.class, id);
| }
|
| @Override
| public List<Airport> getAll() {
| return manager.createQuery("from Airport order by city.country.name").getResultList();
| }
|
| }
|
As you can see I configured it with SUPPORTS transaction attribute, so when there is a transaction all methods in my bean will use it, when there is no transaction context then bean wouldn't begin a new one. So my question is: why i get the exception:
| Caused by: javax.persistence.TransactionRequiredException: EntityManager must be access within a transaction
| at org.jboss.ejb3.entity.ManagedEntityManagerFactory.verifyInTx(ManagedEntityManagerFactory.java:150)
| at org.jboss.ejb3.entity.TransactionScopedEntityManager.persist(TransactionScopedEntityManager.java:174)
| at master.airport.logic.impl.AirportDaoBean.createAirport(AirportDaoBean.java:24)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:597)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
| at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
| at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
| at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
| at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerIntercepto
|
Regards
Adam
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4050744#4050744
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4050744
More information about the jboss-user
mailing list