1 7 package org.jboss.tutorial.tableperinheritance.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 import javax.persistence.PersistenceContext; 15 16 @Stateless 17 @Remote (PetDAO.class) 18 public class PetDAOBean implements PetDAO 19 { 20 @PersistenceContext 21 private EntityManager manager; 22 23 public void createDog(String name, double weight, int bones) 24 { 25 Dog dog = new Dog(); 26 dog.setName(name); 27 dog.setWeight(weight); 28 dog.setNumBones(bones); 29 manager.persist(dog); 30 } 31 32 public void createCat(String name, double weight, int lives) 33 { 34 Cat cat = new Cat(); 35 cat.setName(name); 36 cat.setWeight(weight); 37 cat.setLives(lives); 38 manager.persist(cat); 39 } 40 41 public List findByWeight(double weight) 42 { 43 return manager.createQuery("from Pet p where p.weight < :weight").setParameter("weight", weight).getResultList(); 44 } 45 } 46 | Popular Tags |