package edu.lmu.cs.headmaster.ws.domain;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Entity;
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.OrderColumn;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.annotations.Type;
import org.joda.time.DateTime;
import edu.lmu.cs.headmaster.ws.util.DateTimeXmlAdapter;
/**
* An Event is some activity which may be attended by students.
*/
@Entity
@XmlRootElement
public class Event {
private Long id;
private DateTime dateTime;
private String title;
private String description;
private List<Student> attendees = new ArrayList<Student>();
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@XmlAttribute
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
@Type(type="org.joda.time.contrib.hibernate.PersistentDateTime")
@XmlJavaTypeAdapter(value=DateTimeXmlAdapter.class)
public DateTime getDateTime() {
return dateTime;
}
public void setDateTime(DateTime dateTime) {
this.dateTime = dateTime;
}
@Lob
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
@Lob
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@ManyToMany(cascade = CascadeType.ALL)
@OrderColumn
@JoinTable(
joinColumns = @JoinColumn(name = "event_id"),
inverseJoinColumns = @JoinColumn(name = "student_id")
)
@LazyCollection(LazyCollectionOption.FALSE)
public List<Student> getAttendees() {
return attendees;
}
public void setAttendees(List<Student> attendees) {
this.attendees = attendees;
}
}