I am using not AOP but rather Apache HashCodeBuilder and EqualsBulder
Code:
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
@MappedSuperclass
public abstract class BaseEntity implements Serializable {
private static final long serialVersionUID = 1353453L;
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "hibernate3_sequence")
private Long id;
@Version
@Temporal(TemporalType.TIMESTAMP)
@Column(name = "last_update")
private Date lastUpdate;
public Long getId() {
return id;
}
protected String getHashCodeId() {
if (1 == 1) {
throw new IllegalStateException("You must override this method");
}
return getId() == null ? getNumber().getFullPhoneNumber().toString() : getId().toString();
}
public int hashCode() {
if (1 == 1) {
throw new IllegalStateException("You must override this method");
}
return new HashCodeBuilder(13, 37).append(getHashCodeId()).toHashCode();
}
public boolean equals(Object o) {
return EqualsBuilder.reflectionEquals(this, o);
}
}