how resolve ConstraintViolationException Identity strategy in hibernate problem?

Viewed 38

I'm working an application with java. I am getting this error:

ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (default task-54) DB2 SQL Error:
SQLCODE=-407, SQLSTATE=23502, SQLERRMC=TBSPACEID=2, TABLEID=1298, COLNO=0,

with this exception:

exception occurred: -- javax.persistence.PersistenceException: org.hibernate.exception.ConstraintViolationException: could not execute statement

I looked for a solution and I getting this docs: https://www.ibm.com/docs/en/cfm/2.0.0.3?topic=job-common-sql-errors-during-data-import

it helps me to get which column has the error. it's my primary key.

My primary generated my Station entity is:

@Named
@Entity
@Table(name = "STATION")
@AttributeOverride(name = "id", column = @Column(name = "PK_STATION_ID"))
public class Station extends AbstractEntity {}

my AbstractEntity is:

@MappedSuperclass public abstract class AbstractEntity extends AbstractEntityWithoutId {

/**
 * 
 */
private static final long serialVersionUID = 8088586545483293731L;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

public Long getId() {
    return id;
}

public void setId(Long id) {
    this.id = id;
}

@Override
public String getRefObject() {
    return String.valueOf(super.hashCode());
}

@Override
public boolean equals(Object other) {
    if (this == other) {
        return true;
    }
    if (other == null || getClass() != other.getClass()) {
        return false;
    }
    AbstractEntity that = (AbstractEntity) other;
    if (this.id == null || that.id == null) {
        return super.equals(other);
    }
    return Objects.equals(id, that.id);
}

@Override
public int hashCode() {
    if (id == null) {
        return super.hashCode();
    }
    return Objects.hash(id);
}
}

How to resolve that? thanks in advance.

0 Answers
Related