1: package org.emoticon.library.model;
2:
3: import java.util.ArrayList;
4: import java.util.Date;
5: import java.util.List;
6:
7: import javax.persistence.CascadeType;
8: import javax.persistence.Entity;
9: import javax.persistence.FetchType;
10: import javax.persistence.GeneratedValue;
11: import javax.persistence.Id;
12: import javax.persistence.JoinColumn;
13: import javax.persistence.OneToMany;
14:
15: @Entity
16: public class Book {
17:
18: private Integer id;
19: private String title;
20: private String author;
21: private String description;
22: private String publisher;
23: private int pageNumber;
24: private Date publishTime;
25: private String isbn;
26: private List<Comment> comments = new ArrayList<Comment>();
27:
28:
29: public void addComment(Comment comment){
30: comment.setBook(this);
31: comments.add(comment);
32: }
33:
34: @Id
35: @GeneratedValue
36: public Integer getId() {
37: return id;
38: }
39: public void setId(Integer id) {
40: this.id = id;
41: }
42: public String getTitle() {
43: return title;
44: }
45: public void setTitle(String title) {
46: this.title = title;
47: }
48: public String getAuthor() {
49: return author;
50: }
51: public void setAuthor(String author) {
52: this.author = author;
53: }
54: public String getDescription() {
55: return description;
56: }
57: public void setDescription(String description) {
58: this.description = description;
59: }
60: public String getPublisher() {
61: return publisher;
62: }
63: public void setPublisher(String publisher) {
64: this.publisher = publisher;
65: }
66: public int getPageNumber() {
67: return pageNumber;
68: }
69: public void setPageNumber(int pageNumber) {
70: this.pageNumber = pageNumber;
71: }
72: public Date getPublishTime() {
73: return publishTime;
74: }
75: public void setPublishTime(Date publishTime) {
76: this.publishTime = publishTime;
77: }
78: public String getIsbn() {
79: return isbn;
80: }
81: public void setIsbn(String isbn) {
82: this.isbn = isbn;
83: }
84:
85: @OneToMany(fetch = FetchType.EAGER,
86: cascade = {CascadeType.ALL})
87: @JoinColumn (name = "book_id",
88: nullable = false)
89: @org.hibernate.annotations.IndexColumn(name = "comment_position",
90: nullable = false,
91: base = 1)
92: public List<Comment> getComments() {
93: return comments;
94: }
95:
96: public void setComments(List<Comment> comments) {
97: this.comments = comments;
98: }
99:
100:
101: }