import javax.persistence.* import org.hibernate.annotations.* @Entity class Entry extends AbstractEntity implements Comparable { String title String body @OneToMany(mappedBy="entry") @Sort(type=SortType.NATURAL) SortedSet comments @ManyToMany(mappedBy="entries") @Sort(type=SortType.NATURAL) SortedSet categories int compareTo(Object o) { // descending by createDate and then id def result = o.metaData.createDate.compareTo(metaData.createDate) if (result != 0) { return result } o.id.compareTo(id) } }