KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hibernate > test > annotations > query > Area


1 //$Id: Area.java,v 1.3 2005/06/19 14:20:59 epbernard Exp $
2
package org.hibernate.test.annotations.query;
3
4 import javax.persistence.Column;
5 import javax.persistence.Entity;
6 import javax.persistence.EntityResult;
7 import javax.persistence.FieldResult;
8 import javax.persistence.GeneratorType;
9 import javax.persistence.Id;
10 import javax.persistence.NamedNativeQuery;
11 import javax.persistence.SqlResultSetMapping;
12 import javax.persistence.NamedNativeQueries;
13
14 /**
15  * Example of a entity load incl a join fetching of an associated *ToOne entity
16  * @author Emmanuel Bernard
17  */

18 @Entity
19 @NamedNativeQueries( {
20  @NamedNativeQuery(
21         name="night&area", queryString="select night.id as nid, night.night_duration, night.night_date, area.id as aid, "
22             + "night.area_id, area.name from Night night, Area area where night.area_id = area.id",
23         resultSetMapping="joinMapping")
24         } )
25 @SqlResultSetMapping(name="joinMapping", entities={
26     @EntityResult(name="org.hibernate.test.annotations.query.Night", fields = {
27         @FieldResult(name="id", column="nid"),
28         @FieldResult(name="duration", column="night_duration"),
29         @FieldResult(name="date", column="night_date"),
30         @FieldResult(name="area", column="area_id")
31         }),
32     @EntityResult(name="org.hibernate.test.annotations.query.Area", fields = {
33         @FieldResult(name="id", column="aid"),
34         @FieldResult(name="name", column="name")
35         })
36     }
37 )
38 public class Area {
39     private Integer JavaDoc id;
40     private String JavaDoc name;
41
42     @Id(generate=GeneratorType.AUTO)
43     public Integer JavaDoc getId() {
44         return id;
45     }
46
47     public void setId(Integer JavaDoc id) {
48         this.id = id;
49     }
50     @Column(unique=true)
51     public String JavaDoc getName() {
52         return name;
53     }
54
55     public void setName(String JavaDoc name) {
56         this.name = name;
57     }
58 }
59
Popular Tags