cubetiq-fusion/src/main/java/com/cubetiqs/fusion/data/AbstractEntity.java

46 lines
915 B
Java
Raw Normal View History

2021-07-25 17:44:30 +07:00
package com.cubetiqs.fusion.data;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import com.vaadin.fusion.Nonnull;
@MappedSuperclass
public abstract class AbstractEntity {
@Id
@GeneratedValue
@Nonnull
private Integer id;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
@Override
public int hashCode() {
if (id != null) {
return id.hashCode();
}
return super.hashCode();
}
@Override
public boolean equals(Object obj) {
if (!(obj instanceof AbstractEntity)) {
return false; // null or other class
}
AbstractEntity other = (AbstractEntity) obj;
if (id != null) {
return id.equals(other.id);
}
return super.equals(other);
}
}