added findById(...) with inheritance capabilities
[aramzamzam-commons.git] / aramzamzam-commons / commons-hibernate / src / main / java / net / aramzamzam / commons / hibernate / entities / BasicEntity.java
blob394828c5f50cba1c2f9512dd2082ce7fff217de0
1 package net.aramzamzam.commons.hibernate.entities;
3 import java.io.Serializable;
5 import javax.persistence.GeneratedValue;
6 import javax.persistence.GenerationType;
7 import javax.persistence.Id;
8 import javax.persistence.MappedSuperclass;
10 /**
11 * @author James Carman
13 @SuppressWarnings("unchecked")
14 @MappedSuperclass
15 public class BasicEntity implements Serializable, Comparable {
16 private static final long serialVersionUID = 1L;
17 protected Long id;
19 public int compareTo(Object o) {
20 return String.valueOf(this).compareTo(String.valueOf(o));
23 @Id
24 @GeneratedValue(strategy = GenerationType.AUTO)
25 public Long getId() {
26 return id;
29 // FIXME доступ к этому методу следует сделать private
30 public void setId(Long id) {
31 this.id = id;
34 @Override
35 public int hashCode() {
36 final int prime = 31;
37 int result = 1;
38 result = prime * result + ((id == null) ? 0 : id.hashCode());
39 return result;
41 //see http://roald.jteam.nl/?p=25
42 @Override
43 public boolean equals(Object obj) {
44 if (this == obj)
45 return true;
46 if (obj == null ||
48 getClass() == obj.getClass()
49 || getClass().getSuperclass() == obj.getClass().getSuperclass()
50 || getClass() == obj.getClass().getSuperclass()
51 || getClass().getSuperclass() == obj.getClass()
53 return false;
54 final BasicEntity other = (BasicEntity) obj;
55 if (id != null ? !id.equals(other.getId()) : other.getId() != null)
56 return false;
57 return true;