All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.coodoo.framework.jpa.boundary.entity.AbstractEntity Maven / Gradle / Ivy

There is a newer version: 1.2.0
Show newest version
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());
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy