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.

3
  • Could you add your services class here? Commented Feb 18, 2021 at 3:38
  • SSK, Thank you very much for your time. I already find the reason and fixed it. God bless you! Commented Feb 18, 2021 at 16:23
  • Good to know you have find the solution, could you add it as answer so that others get help if they have ran into similar issue. Commented Feb 19, 2021 at 4:00

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.