[jboss-user] [EJB 3.0] - Transaction Problem
dkalna
do-not-reply at jboss.com
Mon Oct 23 05:27:53 EDT 2006
Hello, please help me, I'm stuck... my code is below, simple Stateless EJB with teo methods, both are REQUIRES_NEW annotated, in first one doSomething I read one row from DB, then I call second method neueTx, which I suppose will run in separate TX. Inside neueTX I call setRollbackOnly() to mark this TX for rollback, so new row (2, Jane) will be rolled back. Now back in doSomething I try to write changes for first row, but then I get following Exception: EntityManager must be access within a transaction
Am I missing something simple?
Thanks a lot
Here is my code:
@Stateless
@Remote(value=SimpleRemote.class)
public class SimpleRemoteBean implements SimpleRemote {
static Logger logger = Logger.getLogger(SimpleRemoteBean.class);
@Resource
SessionContext ctx;
@PersistenceContext
EntityManager em;
@TransactionAttribute(value=TransactionAttributeType.REQUIRES_NEW)
public void doSomething() {
Test test = em.find(Test.class, new Long(1));
neueTx(); // should be running in separate TX, or not?
test.setName("Lukas");
em.merge(test); // I expect this to be writen in DB successfully
}
@TransactionAttribute(value=TransactionAttributeType.REQUIRES_NEW)
private void neueTx() {
Test test = new Test();
test.setId(2);
test.setName("Jane");
em.persist(test);
ctx.setRollbackOnly();
}
}
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3979968#3979968
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3979968
More information about the jboss-user
mailing list