1 package org.hibernate.ce.auction.model; 2 3 import javax.persistence.*; 4 import java.io.Serializable ; 5 import java.util.Date ; 6 7 19 @Entity(access = AccessType.FIELD) 20 @Table(name = "COMMENT") 21 public class Comment implements Serializable , Comparable { 22 23 @Id(generate = GeneratorType.AUTO) 24 @Column(name = "COMMENT_ID") 25 private Long id = null; 26 27 @Version 28 private int version = 0; 29 30 @org.hibernate.annotations.Type(type = "rating") 32 @Column(name = "RATING", nullable = false) 33 private Rating rating; 34 35 @Column(length = 4000, updatable = false) 36 private String text; 37 38 @ManyToOne 39 @JoinColumn(name = "FROM_USER_ID", nullable = false, updatable = false) 40 private User fromUser; 41 42 @ManyToOne 43 @JoinColumn(name = "ABOUT_ITEM_ID", nullable = false, updatable = false) 44 private Item item; 45 46 @Column( nullable = false, updatable = false) 47 private Date created = new Date (); 48 49 52 Comment() {} 53 54 62 public Comment(Rating rating, String text, User fromUser, Item item) { 63 this.rating = rating; 64 this.text = text; 65 this.fromUser = fromUser; 66 this.item = item; 67 } 68 69 71 public Long getId() { return id; } 72 public int getVersion() { return version; } 73 74 public Rating getRating() { return rating; } 75 76 public String getText() { return text; } 77 public void setText(String text) { 78 this.text = text; 79 } 80 81 public User getFromUser() { return fromUser; } 82 83 public Item getItem() { return item; } 84 85 public Date getCreated() { return created; } 86 87 89 public boolean equals(Object o) { 90 if (this == o) return true; 91 if (!(o instanceof Comment)) return false; 92 93 final Comment comment = (Comment) o; 94 95 if (!created.equals(comment.created)) return false; 96 if (!rating.equals(comment.rating)) return false; 97 if (text != null ? !text.equals(comment.text) : comment.text != null) return false; 98 99 return true; 100 } 101 102 public int hashCode() { 103 int result; 104 result = rating.hashCode(); 105 result = 29 * result + (text != null ? text.hashCode() : 0); 106 result = 29 * result + created.hashCode(); 107 return result; 108 } 109 110 public String toString() { 111 return "Comment ('" + getId() + "'), " + 112 "Rating: '" + getRating() + "'"; 113 } 114 115 public int compareTo(Object o) { 116 if (o instanceof Comment) { 117 return this.getCreated().compareTo(((Comment) o).getCreated()); 118 } 119 return 0; 120 } 121 122 124 } 125 | Popular Tags |