Java Reference
In-Depth Information
Creating a query, setting the parameter/s, and running the query may be combined.
If the catalog entry is empty, we don't need to iterate over the
List returned:
if ((catalogEntry.isEmpty()) == true) {
}
If the catalog entry is not empty, iterate over the list returned to retrieve the Catalog
entity instance:
for (Iterator iter = catalogEntry.iterator(); iter.hasNext();) {
catalog = (Catalog) iter.next();
}
If the catalog entry is null , return null , and if the catalog entry is not empty, return
the Catalog entity instance returned. Add another method, persist() , to the
session bean for storing a Catalog entity instance to the database. The persist()
method specifies the Catalog entity bean properties as parameters. In the persist()
method, create a Catalog entity instance from the entity bean properties and persist
the entity instance to the database:
Catalog catalog = new Catalog(catalogId, journal,
publisher, edition, title, author);
em.persist(catalog);
The SessionEJBFaçadeBean session bean class is listed below:
package model;
import java.util.Iterator;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
@Stateless(name = "SessionEJBFaçade", mappedName = "EJB3-SessionEJB")
public class SessionEJBFaçadeBean implements SessionEJBFaçade,
SessionEJBFaçadeLocal {
@PersistenceContext(unitName = "em")
private EntityManager em;
public static final String RemoteJNDIName = "EJB3-
SessionEJB#model.SessionEJBFaçade";
public Catalog validate(String catalogId) {
Catalog catalog = null;
 
Search WWH ::




Custom Search