mirror of
https://github.com/theonedev/onedev.git
synced 2025-12-08 18:26:30 +00:00
51 lines
1.2 KiB
Java
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();
|
|
}
|
|
|
|
}
|