/* * 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.GenerationType; import javax.persistence.Id; import javax.persistence.JoinColumn; import javax.persistence.JoinTable; import javax.persistence.Lob; import javax.persistence.ManyToMany; 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 = "learning_outcome") @NamedQueries({ @NamedQuery(name = "LearningOutcome.findAll", query = "SELECT l FROM LearningOutcome l"), @NamedQuery(name = "LearningOutcome.findById", query = "SELECT l FROM LearningOutcome l WHERE l.id = :id"), @NamedQuery(name = "LearningOutcome.findByCreated", query = "SELECT l FROM LearningOutcome l WHERE l.created = :created"), @NamedQuery(name = "LearningOutcome.findByModified", query = "SELECT l FROM LearningOutcome l WHERE l.modified = :modified")}) public class LearningOutcome implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "LearningOutcomeID") @TableGenerator(name="LearningOutcomeID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_LEARNING_OUTCOME", allocationSize=1) @Basic(optional = false) @Column(name = "id") private Long id; @Lob @Column(name = "title") private String title; @Column(name = "type") private String type; @Basic(optional = false) @Column(name = "created") @Temporal(TemporalType.TIMESTAMP) private Date created; @Basic(optional = false) @Column(name = "modified") @Temporal(TemporalType.TIMESTAMP) private Date modified; @JoinColumn(name = "creator", referencedColumnName = "id") @ManyToOne(optional = false, fetch = FetchType.LAZY) private User creator; @JoinColumn(name = "course", referencedColumnName = "id") @ManyToOne private Course course; @JoinTable(name = "assignment_learning_outcomes", joinColumns = { @JoinColumn(name = "learningoutcome", referencedColumnName = "id")}, inverseJoinColumns = { @JoinColumn(name = "assignment", referencedColumnName = "id")}) @ManyToMany(cascade = {CascadeType.MERGE, CascadeType.PERSIST, CascadeType.REFRESH}) private Collection assignments; @Transient private Long courseId; @OneToMany @JoinTable(name = "category_relationship", joinColumns = { @JoinColumn(name = "parent_id", referencedColumnName = "id"), @JoinColumn(name = "parent_type", referencedColumnName = "type") }, inverseJoinColumns = { @JoinColumn(name = "category_id", referencedColumnName = "id") } ) private Collection categories; @Transient @XmlElementWrapper(name="categoryIds") @XmlElement(name="category") public Collection categoryIds; public LearningOutcome() { } public LearningOutcome(Long id) { this.id = id; } public LearningOutcome(Long id, Date created, Date modified) { this.id = id; this.created = created; this.modified = modified; } 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 Date getCreated() { return created; } public User getCreator() { return creator; } public void setCreator(User creator) { this.creator = creator; } public void setCreated(Date created) { this.created = created; } public Date getModified() { return modified; } public void setModified(Date modified) { this.modified = modified; } public Course getCourse() { return course; } public void setCourse(Course course) { this.course = course; if ( !this.course.getLearningOutcomes().contains(this)) { this.course.addLearningOutcome(this); } } public Long getCourseId() { return courseId; } public void setCourseId(Long cid) { this.courseId = cid; } public Collection getAssignments() { return assignments; } public void setAssignments(Collection assignments) { this.assignments = assignments; } public String getType() { return type; } public void setType(String type) { this.type = type; } public Collection getCategories() { return categories; } public void setCategories(Collection categories) { this.categories = categories; } public void setCategoryIds(Collection categoryIds) { this.categoryIds = categoryIds; } @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 LearningOutcome)) { return false; } LearningOutcome other = (LearningOutcome) 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.LearningOutcome[id=" + id + "]"; } }