1 22 package org.jboss.ejb3.test.txexceptions; 23 24 import org.jboss.ejb3.tx.TxUtil; 25 26 import javax.persistence.EntityManager; 27 import javax.naming.InitialContext ; 28 import javax.transaction.TransactionManager ; 29 import javax.transaction.Transaction ; 30 31 37 public class RequiresNewTest 38 { 39 public static void doit() throws Exception 40 { 41 InitialContext ctx = new InitialContext (); 42 EntityManager em = (EntityManager)ctx.lookup("java:/SimpleEntityManager"); 43 TransactionManager tm = TxUtil.getTransactionManager(); 44 45 tm.begin(); 46 SimpleEntity entity = new SimpleEntity(); 47 entity.setStuff("hello"); 48 entity.setId(11223123); 49 em.persist(entity); 50 em.flush(); 51 52 Transaction tx = tm.suspend(); 53 tm.begin(); 54 if (em.contains(entity)) throw new RuntimeException ("entity should not be managed as we should have a different session"); 55 tm.commit(); 56 tm.resume(tx); 57 tm.commit(); 58 } 59 } 60 | Popular Tags |