1 package info.ejava.examples.jaxrs.todos.bo; 2 3 import javax.persistence.Column; 4 import javax.persistence.Entity; 5 import javax.persistence.FetchType; 6 import javax.persistence.GeneratedValue; 7 import javax.persistence.GenerationType; 8 import javax.persistence.Id; 9 import javax.persistence.JoinColumn; 10 import javax.persistence.ManyToOne; 11 import javax.persistence.NamedQuery; 12 import javax.persistence.Table; 13 14 @Entity 15 @Table(name="ETODOS_TODO_ITEM") 16 @NamedQuery(name="TodoItem.getTodoItem", 17 query="select ti from TodoItem ti where ti.todoList.name=:listName and ti.name=:itemName" 18 ) 19 @NamedQuery(name="TodoItem.deleteTodoItem", 20 query="delete from TodoItem ti where ti.id=:id") 21 public class TodoItem { 22 @Id @GeneratedValue(strategy=GenerationType.SEQUENCE) 23 private int id; 24 25 @Column(name="NAME", length=32, nullable=false) 26 private String name; 27 28 @Column(name="ITEM_PRIORITY", nullable=false) 29 private int priority; 30 31 @ManyToOne(optional=false, fetch=FetchType.LAZY) 32 @JoinColumn(name="TODO_LIST_ID", nullable=false, updatable=false) 33 private TodoList todoList; 34 35 public int getId() { 36 return id; 37 } 38 public void setId(int id) { 39 this.id = id; 40 } 41 public String getName() { 42 return name; 43 } 44 public void setName(String name) { 45 this.name = name; 46 } 47 public int getPriority() { 48 return priority; 49 } 50 public void setPriority(int priority) { 51 this.priority = priority; 52 } 53 54 public void setTodoList(TodoList todoList) { 55 this.todoList = todoList; 56 } 57 public TodoList getTodoList() { 58 return todoList; 59 } 60 61 @Override 62 public String toString() { 63 StringBuilder builder = new StringBuilder(); 64 builder.append("TodoItem [id=").append(id) 65 .append(", name=").append(name) 66 .append(", priority=").append(priority) 67 .append("]"); 68 return builder.toString(); 69 } 70 }