1 22 package org.jboss.ejb3.test.mdbtransactions; 23 24 import javax.ejb.Remote ; 25 import javax.ejb.Stateless ; 26 import javax.ejb.TransactionAttribute ; 27 import javax.ejb.TransactionAttributeType ; 28 import javax.persistence.EntityManager; 29 import javax.persistence.PersistenceContext; 30 31 import org.jboss.annotation.ejb.RemoteBinding; 32 import org.jboss.logging.Logger; 33 34 37 @Stateless (name="Stateless") 38 @Remote (StatelessFacade.class) 39 @RemoteBinding(jndiBinding = "StatelessFacade") 40 public class StatelessFacadeBean implements StatelessFacade 41 { 42 private static final Logger log = Logger.getLogger(StatelessFacadeBean.class); 43 44 private @PersistenceContext EntityManager manager; 45 46 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 47 public void clear(Entity entity) 48 { 49 try 50 { 51 entity = manager.find(Entity.class, entity.getId()); 52 if (entity != null) 53 manager.remove(entity); 54 } 55 catch (Throwable t) 56 { 57 t.printStackTrace(); 58 } 59 } 60 61 @TransactionAttribute (TransactionAttributeType.REQUIRES_NEW) 62 public void persist(Entity entity) 63 { 64 try 65 { 66 manager.persist(entity); 67 } 68 catch (Throwable t) 69 { 70 t.printStackTrace(); 71 } 72 } 73 } 74 | Popular Tags |