View Javadoc
1   package ejava.jpa.examples.query;
2   
3   import javax.persistence.*;
4   
5   @Entity 
6   @Table(name="JPAQL_CUSTOMER")
7   @NamedQueries({
8       @NamedQuery(name="Customer.getCustomersByName",
9               query="select c from Customer c " +
10                      "where c.firstName like :first AND c.lastName like :last"),
11      @NamedQuery(name="Customer.getCustomerPurchases",
12              query="select s from Sale s " +
13                      "where s.buyerId=:custId")
14  })
15  /* issues compiling this with hibernate3-plugin
16  @NamedNativeQueries({
17  	@NamedNativeQuery(name="Customer.getCustomerRows", 
18  			query="select * from JPAQL_CUSTOMER c " +
19                    "where c.FIRST_NAME = ?1")
20  })
21  */
22  public class Customer {
23      @Id @GeneratedValue 
24      @Column(name="CUSTOMER_ID")    
25      private long id;
26      
27      @Column(name="FIRST_NAME", length=16, nullable=true)
28      private String firstName;
29      
30      @Column(name="LAST_NAME", length=16, nullable=true)
31      private String lastName;
32      
33      public long getId() { return id; }
34  
35      public String getFirstName() { return firstName; }
36      public Customer setFirstName(String firstName) {
37          this.firstName = firstName;
38          return this;
39      }
40      
41      public String getLastName() { return lastName; }
42      public Customer setLastName(String lastName) {
43          this.lastName = lastName;
44          return this;
45      }
46      
47      public String toString() {
48          StringBuilder text = new StringBuilder();
49          text.append("firstName=" + firstName);
50          text.append(", lastName=" + lastName);
51          return text.toString();
52      }
53  }