Book.java

Download Book.java

 1: /* Java SE JPA demo, using EclipseLink and embedded JavaDB
 2:  * @author Wayne Pollock, Tampa Florida USA
 3:  *
 4:  * Note the use of JPA annotations to define the primary key and
 5:  * have its value auto-generated.  Constraints on other columns
 6:  * are defined using the @Column annotation.  There are many more
 7:  * annotations to override any JPA defaults and control behavior;
 8:  * this is indeed a trivial example.
 9:  */
10: 
11: package com.wpollock.jpademo;
12: 
13: import jakarta.persistence.*;
14: 
15: @Entity
16: public class Book {
17:    @Id @GeneratedValue
18:    private int id;
19:    private String title;
20:    @Column (length = 1024 )     // Max num of characters
21:    private String description;
22:    @Column( nullable = false )  // NOT NULL
23:    private String isbn;
24:    private Float price;
25:    private String author;
26: 
27:    public Book () { // A no-arg constructor is required and used by JPA.
28:    }
29: 
30:    public int getId () { return id; }  // Read-only; no "set" method.
31: 
32:    public String getTitle () { return title; }
33:    public void setTitle ( String title ) { this.title = title; }
34: 
35:    public String getDescription () { return description; }
36:    public void setDescription ( String description ) {
37:       this.description = description;
38:    }
39: 
40:    public String getIsbn () { return isbn; }
41:    public void setIsbn ( String isbn ) { this.isbn = isbn; }
42: 
43:    public Float getPrice () { return price; }
44:    public void setPrice ( Float price ) { this.price = price; }
45: 
46:    public String getAuthor () { return author; }
47:    public void setAuthor ( String author ) { this.author = author; }
48: }