robin e54cea564b 1. add tapestry support
2. enhance wicket support
3. merge parent.plugin, parent.product with parent.general
2012-05-22 22:07:19 +08:00

51 lines
1.2 KiB
Java

package com.pmease.commons.hibernate;
import java.io.Serializable;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.hibernate.annotations.GenericGenerator;
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(generator="increment")
@GenericGenerator(name="increment", strategy="increment")
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public boolean equals(Object other) {
if (!(other instanceof AbstractEntity))
return false;
if (this == other)
return true;
AbstractEntity otherEntity = (AbstractEntity) other;
if (getId() == null && otherEntity.getId() == null)
return super.equals(other);
else
return new EqualsBuilder().append(getId(), otherEntity.getId()).isEquals();
}
public int hashCode() {
if (getId() == null)
return super.hashCode();
else
return new HashCodeBuilder(17, 37).append(getId()).toHashCode();
}
}