KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > tutorial > tableperinheritance > 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.tableperinheritance.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 import javax.persistence.PersistenceContext;
15
16 @Stateless JavaDoc
17 @Remote JavaDoc(PetDAO.class)
18 public class PetDAOBean implements PetDAO
19 {
20    @PersistenceContext
21    private EntityManager manager;
22
23    public void createDog(String JavaDoc 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 JavaDoc 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 JavaDoc findByWeight(double weight)
42    {
43       return manager.createQuery("from Pet p where p.weight < :weight").setParameter("weight", weight).getResultList();
44    }
45 }
46
Popular Tags