whats so bad about a year class ? @Entity @ClassDescriptor(hasCyclicRelationships = true, nonVisual = false) public class Year implements Cloneable, Serializable { private static final Log log = LogFactory.getLog(Year.class);
private Integer id = null; private Integer yearStart = new Integer("0"); private Integer yearEnd = new Integer("0"); private League league = null; private Long created = new Long(GregorianCalendar.getInstance() .getTimeInMillis()); private Long accessed = new Long(GregorianCalendar.getInstance() .getTimeInMillis()); /** * CTOR */ public Year() { } public Year(Year dto) { try { BeanUtils.copyProperties(this, dto); } catch (Exception e) { log.error(e.toString()); e.printStackTrace(); } } /** * Accessor for id * * @return Integer * @hibernate.id generator-class="increment" unsaved-value="-1" * type="java.lang.Integer" unique="true" insert="true" */ @Id @GeneratedValue(strategy = GenerationType.AUTO) @PropertyDescriptor(readOnly = true) public Integer getId() { return id; } @PropertyDescriptor public Integer getYearStart() { return yearStart; } @PropertyDescriptor public Integer getYearEnd() { return yearEnd; } @ManyToOne public League getLeague() { return league; } @PropertyDescriptor(nonVisual = true, searchable = false) public Long getCreated() { return created; } @PropertyDescriptor(nonVisual = true, searchable = false) public Long getAccessed() { return accessed; } @Transient @PropertyDescriptor(nonVisual = true, searchable = false) public String getCreatedAsString() { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(created.longValue()); return DatePattern.sdf.format(cal.getTime()); } @Transient @PropertyDescriptor(nonVisual = true, searchable = false) public String getAccessedAsString() { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(accessed.longValue()); return DatePattern.sdf.format(cal.getTime()); } public void setId(Integer id) { this.id = id; } public void setYearStart(Integer yearStart) { this.yearStart = yearStart; } public void setYearEnd(Integer yearEnd) { this.yearEnd = yearEnd; } public void setLeague(League league) { this.league = league; } @Transient @PropertyDescriptor(nonVisual = true, searchable = false) public void setCreatedAsString(String value) throws Exception { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime()); this.created = new Long(cal.getTimeInMillis()); } @Transient @PropertyDescriptor(nonVisual = true, searchable = false) public void setAccessedAsString(String value) throws Exception { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(DatePattern.sdf.parse(value).getTime()); this.accessed = new Long(cal.getTimeInMillis()); } public void setAccessed(Long accessed) { this.accessed = accessed; } public void setCreated(Long created) { this.created = created; } @Override public int hashCode() { return (getId() != null ? getId().hashCode() : 0); } @Override public Year clone() { return new Year(this); } /** * equals and hashCode need to be hammered out for hibernate to work * properly * * Check the matrix summary for best practices at * http://www.hibernate.org/109.html */ @Override public boolean equals(Object rhs) { if (this == rhs) return true; // instance equality if (rhs == null || getClass() != rhs.getClass()) return false; // null/class equality final Year castedObject = (Year) rhs; return !(getId() != null ? !getId().equals(castedObject.getId()) : castedObject.getId() != null); } public String toString() { return getYearStart().toString() + "/" + getYearEnd().toString(); } }