1 22 package org.jboss.ejb3.test.regression.ejbthree290; 23 24 import javax.ejb.Stateless ; 25 import javax.persistence.PersistenceContext; 26 import javax.persistence.EntityManager; 27 import javax.persistence.EntityNotFoundException; 28 import javax.ejb.Remote ; 29 import javax.ejb.EJB ; 30 31 37 @Stateless 38 @Remote (DAO.class) 39 public class DAOBean implements DAO 40 { 41 @PersistenceContext EntityManager manager; 42 @EJB DeleteLocal local; 43 44 public MyEntity create() 45 { 46 MyEntity e = new MyEntity(); 47 e.name = "Bill"; 48 manager.persist(e); 49 return e; 50 } 51 52 public void findAndDelete(int id) throws Exception 53 { 54 MyEntity e = manager.find(MyEntity.class, id); 55 local.removeEntity(e.id); 56 try 57 { 58 manager.refresh(e); 59 } 60 catch (EntityNotFoundException e1) 61 { 62 return; } 64 throw new RuntimeException ("Expected EntityNotFoundException"); 65 } 66 67 public void merge(MyEntity e) throws Exception 68 { 69 MyEntity managedEntity = manager.find(MyEntity.class, e.id); 72 managedEntity.name="Joe"; 73 manager.remove(managedEntity); 74 try 75 { 76 manager.merge(managedEntity); 77 } 78 catch (IllegalArgumentException e1) 79 { 80 return; 81 } 82 throw new RuntimeException ("expected IllegalArgumentException"); 83 } 84 85 public void mergeAfterRemove(MyEntity e) throws Exception 86 { 87 e = manager.merge(e); 88 manager.remove(e); 89 try 90 { 91 manager.merge(e); 92 } 93 catch (IllegalArgumentException e1) 94 { 95 return; 96 } 97 throw new RuntimeException ("expected IllegalArgumentException"); 98 } 99 100 } 101 | Popular Tags |