1 22 package org.jboss.ejb3.test.pkg; 23 24 25 import javax.ejb.Remote ; 26 import javax.ejb.Stateless ; 27 import javax.persistence.EntityManager; 28 import javax.persistence.NamedQuery; 29 import javax.persistence.PersistenceContext; 30 import javax.persistence.Query; 31 32 38 @Stateless 39 @Remote (EntityTest.class) 40 @NamedQuery(name="customerById", query="from Customer c where c.id = :id") 41 public class EntityTestBean implements EntityTest 42 { 43 @PersistenceContext 44 private EntityManager manager; 45 46 public Customer createCustomer() 47 { 48 Customer c = new Customer(); 49 c.setName("Bill"); 50 c.setStreet("Landsdown Street"); 51 c.setCity("Boston"); 52 c.setState("MA"); 53 c.setZip("02114"); 54 manager.persist(c); 55 return c; 56 } 57 58 public Customer findByCustomerId(Long id) 59 { 60 Query query = manager.createNamedQuery("customerById"); 61 return (Customer)query.setParameter("id", id).getSingleResult(); 62 } 63 } 64 | Popular Tags |