/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package ee.tlu.htk.dippler.entities; import java.io.Serializable; import java.util.Collection; import java.util.Date; import javax.persistence.Basic; import javax.persistence.CascadeType; import javax.persistence.Column; import javax.persistence.Entity; import javax.persistence.FetchType; import javax.persistence.GeneratedValue; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.Lob; import javax.persistence.ManyToOne; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.persistence.TableGenerator; import javax.persistence.Temporal; import javax.persistence.TemporalType; import javax.persistence.Transient; import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElementWrapper; import javax.xml.bind.annotation.XmlRootElement; /** * * @author metz */ @XmlRootElement @Entity @Table(name = "courseblog_post") @NamedQueries({ @NamedQuery(name = "CourseblogPost.findAll", query = "SELECT c FROM CourseblogPost c"), @NamedQuery(name = "CourseblogPost.findById", query = "SELECT c FROM CourseblogPost c WHERE c.id = :id"), @NamedQuery(name = "CourseblogPost.findByTitle", query = "SELECT c FROM CourseblogPost c WHERE c.title = :title"), @NamedQuery(name = "CourseblogPost.findByCreated", query = "SELECT c FROM CourseblogPost c WHERE c.created = :created"), @NamedQuery(name = "CourseblogPost.findByModified", query = "SELECT c FROM CourseblogPost c WHERE c.modified = :modified"), @NamedQuery(name = "CourseblogPost.findByHidden", query = "SELECT c FROM CourseblogPost c WHERE c.hidden = :hidden"), @NamedQuery(name = "CourseblogPost.findByCourseNotHidden", query = "SELECT c FROM CourseblogPost c WHERE c.course = :course AND c.hidden = 0 ORDER BY c.created DESC")}) public class CourseblogPost implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "CourseBlogPostID") @TableGenerator(name="CourseBlogPostID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_COURSE_BLOGPOST", allocationSize=1) @Basic(optional = false) @Column(name = "id") private Long id; @Column(name = "title") private String title; @Lob @Column(name = "body") private String body; @Basic(optional = false) @Column(name = "created") @Temporal(TemporalType.TIMESTAMP) private Date created = new Date(); @Basic(optional = false) @Column(name = "modified") @Temporal(TemporalType.TIMESTAMP) private Date modified = new Date(); @Basic(optional = false) @Column(name = "hidden") private boolean hidden; @JoinColumn(name = "creator", referencedColumnName = "id") @ManyToOne(optional = false, fetch = FetchType.LAZY) private User user; @JoinColumn(name = "course") @ManyToOne(optional = false, fetch = FetchType.LAZY) private Course course; @OneToMany(cascade = CascadeType.ALL, mappedBy = "courseblogPost", fetch = FetchType.LAZY) private Collection courseblogComments; /*@OneToMany @JoinTable(name = "tag_relationship", joinColumns = @JoinColumn(name = "parent_id", referencedColumnName = "id", columnDefinition="parent_type=courseblog_post"), inverseJoinColumns = @JoinColumn(name = "tag_id", referencedColumnName = "id") ) private Collection tags;*/ @Transient @XmlElementWrapper(name="tags") @XmlElement(name="tag") public Collection tags; @OneToMany @JoinTable(name = "category_relationship", joinColumns = @JoinColumn(name = "parent_id", referencedColumnName = "id", columnDefinition="parent_type=courseblog_post"), inverseJoinColumns = @JoinColumn(name = "category_id", referencedColumnName = "id") ) private Collection categories; @Transient @XmlElementWrapper(name="tags") @XmlElement(name="tag") public Collection tagIds; @Transient @XmlElementWrapper(name="categories") @XmlElement(name="category") public Collection categoryIds; public CourseblogPost() { } public CourseblogPost(Long id) { this.id = id; } public CourseblogPost(Long id, Date created, Date modified, boolean hidden) { this.id = id; this.created = created; this.modified = modified; this.hidden = hidden; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public String getBody() { return body; } public void setBody(String body) { this.body = body; } public Date getCreated() { return created; } public void setCreated(Date created) { this.created = created; } public Date getModified() { return modified; } public void setModified(Date modified) { this.modified = modified; } public boolean getHidden() { return hidden; } public void setHidden(boolean hidden) { this.hidden = hidden; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; if ( !this.course.getPosts().contains(this) ) { this.course.addPost(this); } } public Collection getCourseblogComments() { return courseblogComments; } public void setCourseblogComments(Collection courseblogCommentCollection) { this.courseblogComments = courseblogCommentCollection; } public void setTags(Collection cts) { this.tags = cts; } public Collection getCategories() { return categories; } public void setCategories(Collection ccs) { this.categories = ccs; } public void setTagIds(Collection id) { this.tagIds = id; } public void setCategoryIds(Collection id) { this.categoryIds = id; } @Override public int hashCode() { int hash = 0; hash += (id != null ? id.hashCode() : 0); return hash; } @Override public boolean equals(Object object) { // TODO: Warning - this method won't work in the case the id fields are not set if (!(object instanceof CourseblogPost)) { return false; } CourseblogPost other = (CourseblogPost) object; if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) { return false; } return true; } @Override public String toString() { return "ee.tlu.htk.dippler.entities.CourseblogPost[id=" + id + "]"; } }