KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > singleinheritance > bean > PetDAOBean


1 /*
2  * JBoss, the OpenSource J2EE webOS
3  *
4  * Distributable under LGPL license.
5  * See terms of license at gnu.org.
6  */

7 package org.jboss.tutorial.singleinheritance.bean;
8
9 import java.util.List JavaDoc;
10 import javax.ejb.Remote JavaDoc;
11 import javax.ejb.Stateless JavaDoc;
12 import javax.persistence.EntityManager;
13 import javax.persistence.PersistenceContext;
14
15 @Stateless JavaDoc
16 @Remote JavaDoc(PetDAO.class)
17 public class PetDAOBean implements PetDAO
18 {
19    @PersistenceContext
20    private EntityManager manager;
21
22    public void createDog(String JavaDoc 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 JavaDoc 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 JavaDoc findByWeight(double weight)
41    {
42       return manager.createQuery("from Pet p where p.weight < :weight").setParameter("weight", weight).getResultList();
43    }
44 }
45
Popular Tags