Java Reference
In-Depth Information
The corresponding database row gets deleted from the Catalog table. Subsequently,
create and run a query to list all the entity instances mapped to the database. The
session bean class, CatalogTestBean , is listed next:
package ejb3;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
/**
* Session Bean implementation class CatalogTestBean
*/
@Stateless(mappedName = "EJB3-SessionEJB")
public class CatalogTestBean implements CatalogTestBeanRemote {
@PersistenceContext(unitName = "em")
EntityManager em;
/**
* Default constructor.
*/
public CatalogTestBean() {
// TODO Auto-generated constructor stub
}
public String test() {
Catalog catalog = new Catalog(new Integer(1), "Oracle Magazine",
"Oracle Publishing", "September-October 2009",
"Put Your Arrays in a Bind","Mark Williams");
em.persist(catalog);
Catalog catalog2 = new Catalog(new Integer(2), "Oracle Magazine",
"Oracle Publishing", "September-October 2009",
"Oracle Fusion Middleware 11g: The Foundation for Innovation",
"David Baum");
em.persist(catalog2);
Catalog catalog3 = new Catalog(new Integer(3), "Oracle Magazine",
"Oracle Publishing", "September-October 2009",
"Integrating Information","David Baum");
em.persist(catalog3);
String retValue = "<b>Catalog Entries: </b>";
List catalogEntry = em.createQuery("SELECT c from Catalog c
where c.author=:name").setParameter("name",
"David Baum").getResultList();
for (Iterator iter = catalogEntry.iterator(); iter.hasNext(); ) {
 
Search WWH ::




Custom Search