Java Reference
In-Depth Information
Similarly, all the titles may be listed and all the Catalog entity instances may be
listed. An entity instance may be removed using the remove() method. To remove
an entity instance, create the entity instance, merge the entity instance with the
entity manager using the merge() method, and remove the entity instance using the
remove() method:
Catalog catalog2 =new Catalog("Jonas Jacobi", "Nov-Dec 2004",
new Integer(2),"Oracle Magazine", "Oracle Publishing",
"From ADF UIX to JSF");
Catalog c2 = em.merge(catalog2);
Annotate the test() method with the @TransactionAttribute annotation with
type set to REQUIRES_NEW , which implies that a new transaction is created for the
test() method in the session bean:
The session bean class is listed as follows:
package model;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.FlushModeType;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceUnit;
import javax.persistence.Query;
import javax.transaction.UserTransaction;
@Stateless(name = "CatalogSessionEJB", mappedName = "EJB3-SessionEJB")
public class CatalogSessionEJBBean implements CatalogSessionEJB {
@PersistenceContext(unitName = "em",
type = PersistenceContextType.TRANSACTION)
EntityManager em;
public CatalogSessionEJBBean() {
Search WWH ::

Custom Search