io.coodoo.framework.jpa.boundary.entity.AbstractEntity Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of coodoo-jpa-essentials Show documentation
Show all versions of coodoo-jpa-essentials Show documentation
Essential JPA entities and functionality
package io.coodoo.framework.jpa.boundary.entity;
import java.io.Serializable;
import javax.persistence.Column;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
/**
* Base identification entity
*
* @author coodoo GmbH (coodoo.io)
*/
@SuppressWarnings("serial")
@MappedSuperclass
public abstract class AbstractEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
protected Long id;
public void setId(Long id) {
this.id = id;
}
public Long getId() {
return id;
}
@Override
public String toString() {
return "id=" + id;
}
@Override
public int hashCode() {
if (getId() != null) {
return getId().hashCode();
} else {
return super.hashCode();
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null || !(obj instanceof AbstractEntity)) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
if (((AbstractEntity) obj).getId() == null) {
return false;
}
return ((AbstractEntity) obj).getId().equals(getId());
}
}