1 7 package org.jboss.tutorial.singleinheritance.bean; 8 9 import java.util.List ; 10 import javax.ejb.Remote ; 11 import javax.ejb.Stateless ; 12 import javax.persistence.EntityManager; 13 import javax.persistence.PersistenceContext; 14 15 @Stateless 16 @Remote (PetDAO.class) 17 public class PetDAOBean implements PetDAO 18 { 19 @PersistenceContext 20 private EntityManager manager; 21 22 public void createDog(String name, double weight, int bones) 23 { 24 Dog dog = new Dog(); 25 dog.setName(name); 26 dog.setWeight(weight); 27 dog.setTrick("Sit"); 28 manager.persist(dog); 29 } 30 31 public void createCat(String name, double weight, int lives) 32 { 33 Cat cat = new Cat(); 34 cat.setName(name); 35 cat.setWeight(weight); 36 cat.setHairball("#$@#%@"); 37 manager.persist(cat); 38 } 39 40 public List findByWeight(double weight) 41 { 42 return manager.createQuery("from Pet p where p.weight < :weight").setParameter("weight", weight).getResultList(); 43 } 44 } 45 | Popular Tags |