1 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 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 id; 40 private String name; 41 42 @Id(generate=GeneratorType.AUTO) 43 public Integer getId() { 44 return id; 45 } 46 47 public void setId(Integer id) { 48 this.id = id; 49 } 50 @Column(unique=true) 51 public String getName() { 52 return name; 53 } 54 55 public void setName(String name) { 56 this.name = name; 57 } 58 } 59 | Popular Tags |