/* * 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 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.ManyToMany; import javax.persistence.NamedQueries; import javax.persistence.NamedQuery; import javax.persistence.OneToMany; import javax.persistence.OneToOne; import javax.persistence.Table; import javax.persistence.TableGenerator; /** * * @author metz */ @Entity @Table(name = "organization") @NamedQueries({ @NamedQuery(name = "Organization.findAll", query = "SELECT o FROM Organization o"), @NamedQuery(name = "Organization.findById", query = "SELECT o FROM Organization o WHERE o.id = :id"), @NamedQuery(name = "Organization.findByName", query = "SELECT o FROM Organization o WHERE o.name = :name")}) public class Organization implements Serializable { @OneToMany(cascade = CascadeType.ALL, mappedBy = "organization") private Collection tagRelationshipCollection; private static final long serialVersionUID = 1L; @Id @GeneratedValue(generator = "OrganizationID") @TableGenerator(name="OrganizationID", table="id_gen", pkColumnName="ID_NAME", valueColumnName = "ID_VAL", pkColumnValue="LAST_ORGANIZATION", allocationSize=1) @Basic(optional = false) @Column(name = "id") private Long id; @Basic(optional = false) @Column(name = "name") private String name; @ManyToMany(mappedBy = "organizations") private Collection users; @OneToMany(mappedBy = "organization") private Collection courses; @JoinColumn(name = "admin", referencedColumnName = "id") @OneToOne private User user; @OneToOne(mappedBy = "organization", fetch = FetchType.LAZY) private Client client; public Organization() { } public Organization(Long id) { this.id = id; } public Organization(Long id, String name) { this.id = id; this.name = name; } public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } public Collection getUsers() { return users; } public void setUserCollection(Collection userCollection) { this.users = userCollection; } public Collection getCourses() { return courses; } public void setCourses(Collection courseCollection) { this.courses = courseCollection; } public User getUser() { return user; } public void setUser(User user) { this.user = user; } public Client getClient() { return client; } public void setClient(Client client) { this.client = client; } @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 Organization)) { return false; } Organization other = (Organization) 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.Organization[id=" + id + "]"; } public Collection getTagRelationshipCollection() { return tagRelationshipCollection; } public void setTagRelationshipCollection(Collection tagRelationshipCollection) { this.tagRelationshipCollection = tagRelationshipCollection; } }