0

I am writing an Entity class Result, and it has a ONETOONE mapping to another entity UpstreamResult. When I do a save() method. In a spring boot concurrence situation, sometimes, the child entity get inserted not updated and throw JdbcSQLIntegrityConstraintViolationException: Unique index or primary key violation

Parent Class:

@Table(name = "RESULT")
public class Result implements Serializable {

    @OneToOne(cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinColumn(name = "UPSTREAMSIGNALTESTRESULT_ID", referencedColumnName = "uuid", unique=true)
    private UpStreamTestResult upStreamSignalTestResult;

  
    ...

Child Class:

@Table(name = "UPSTREAMTESTRESULT")
public class UpStreamTestResult implements Serializable {

    @Id
    private String uuid;

    @Override
    public boolean equals(Object o) {
        if (!(o instanceof UpStreamTestResult)) {
            return false;
        }

        UpStreamTestResult that = (UpStreamTestResult) o;

        if (this == that) {
            return true;
        }

        return this.getUuid().equals(that.getUuid());
    }

    @Override
    public int hashCode() {
        return this.getUuid().hashCode();
    }

.....

If I run my application once, it works fine. But when I run my application aync and high concurrance, , and all instance connect to one DB, it throw the above exception.

Zha Jikun
  • 11
  • 2

0 Answers0