package org.jdal.test.model; import java.util.Date; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.ManyToOne; import javax.persistence.Table; import javax.validation.constraints.NotNull; import org.hibernate.validator.constraints.NotEmpty; import org.jdal.beans.StaticMessageSource; @javax.persistence.Entity @Table(name="books") public class Book { @Id @GeneratedValue(strategy=GenerationType.AUTO) private Long id; @NotEmpty private String name = ""; @NotNull @ManyToOne @JoinColumn(name="authorid") private Author author; @NotNull @ManyToOne @JoinColumn(name="categoryid") private Category category; private String isbn = ""; private Date publishedDate; /** * @return the author */ public Author getAuthor() { return author; } /** * @param author the author to set */ public void setAuthor(Author author) { this.author = author; } /** * @return the category */ public Category getCategory() { return category; } /** * @param category the category to set */ public void setCategory(Category category) { this.category = category; } /** * @return the isbn */ public String getIsbn() { return isbn; } /** * @param isbn the isbn to set */ public void setIsbn(String isbn) { this.isbn = isbn; } /** * @return the publishedDate */ public Date getPublishedDate() { return publishedDate; } /** * @param publishedDate the publishedDate to set */ public void setPublishedDate(Date publishedDate) { this.publishedDate = publishedDate; } /** * @return the id */ public Long getId() { return id; } /** * @param id the id to set */ public void setId(Long id) { this.id = id; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } public String toString() { return id == null? StaticMessageSource.getMessage("New") : name; } /** * {@inheritDoc} */ @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((name == null) ? 0 : name.hashCode()); return result; } /** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; Book other = (Book) obj; if (name == null) { if (other.name != null) return false; } else if (!name.equals(other.name)) return false; return true; } }