I’m currently using Hibernate 5.2 and trying to upgrade step by step to the latest version. When upgrading from 5.2 to 5.3 I run into a weird phenomenon.
Given the following entities (yes, those are about spring batch jobs):
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToOne;
import javax.persistence.Table;
@Entity
@Table(name = "job__step_execution")
public class StepExecution
{
@Id
@Column(name = "step_execution_id", nullable = false)
private Long stepExecutionId;
// ... Some other simple mapped columns here
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "step_execution_id")
private StepExecutionContext stepExecutionContext;
@ManyToOne
@JoinColumn(name = "job_execution_id", nullable = false)
private JobExecution jobExecution;
// ... just getters and setters here
}
@Entity
@Table(name = "job__step_execution_context")
public class StepExecutionContext
{
@Id
@Column(name = "step_execution_id")
private Long stepExecutionId;
@Column(name = "short_context")
private String shortContext = null;
// One additional unmapped column in the table
// @Column(name = "serialized_context")
// private String serializedContext = null;
// ... just getters and setters here
}
one of my integration test that tries to clean up started job executions (always) fails:
Behavior with 5.2:
2022-05-19 10:49:48,136 DEBUG [TestNG-test=Ifa-1] {0c2fb533-87d1-40b1-9418-358b0c9645c3} e.j.s.j.d.i.JobDomainImpl: Found the following contexts for the step execution: [31]
2022-05-19 10:49:48,143 DEBUG [TestNG-test=Ifa-1] {0c2fb533-87d1-40b1-9418-358b0c9645c3} e.j.s.j.d.i.JobDomainImpl: removeById(jobExecutionId) called
2022-05-19 10:49:48,143 DEBUG [TestNG-test=Ifa-1] {0c2fb533-87d1-40b1-9418-358b0c9645c3} o.h.SQL:
delete
from
job__step_execution_context
where
step_execution_id=?
2022-05-19 10:49:48,148 TRACE [TestNG-test=Ifa-1] {0c2fb533-87d1-40b1-9418-358b0c9645c3} o.h.t.d.s.BasicBinder: binding parameter [1] as [BIGINT] - [31]
2022-05-19 10:49:48,151 DEBUG [TestNG-test=Ifa-1] {0c2fb533-87d1-40b1-9418-358b0c9645c3} o.h.SQL:
delete
from
job__step_execution
where
step_execution_id=?
2022-05-19 18:49:48,152 TRACE [TestNG-test=Ifa-1] {0c2fb533-87d1-40b1-9418-358b0c9645c3} o.h.t.d.s.BasicBinder: binding parameter [1] as [BIGINT] - [31]
Behavior with 5.3:
2022-05-19 10:07:56,023 DEBUG [TestNG-test=Ifa-1] {f3c51736-d50e-4c34-97e6-da32a67b5255} e.j.s.j.d.i.JobDomainImpl: Found the following contexts for the step execution: [31]
2022-05-19 10:07:56,043 DEBUG [TestNG-test=Ifa-1] {f3c51736-d50e-4c34-97e6-da32a67b5255} e.j.s.j.d.i.JobDomainImpl: removeById(jobExecutionId) called
2022-05-19 10:07:56,044 DEBUG [TestNG-test=Ifa-1] {f3c51736-d50e-4c34-97e6-da32a67b5255} o.h.SQL:
delete
from
job__step_execution
where
step_execution_id=?
2022-05-19 10:07:56,046 TRACE [TestNG-test=Ifa-1] {f3c51736-d50e-4c34-97e6-da32a67b5255} o.h.t.d.s.BasicBinder: binding parameter [1] as [BIGINT] - [31]
2022-05-19 10:07:56,078 ERROR [TestNG-test=Ifa-1] {f3c51736-d50e-4c34-97e6-da32a67b5255} o.h.e.j.b.i.BatchingBatch: HHH000315: Exception executing batch [java.sql.BatchUpdateException: Key value for constraint (informix.job__step_execution__primary_key) is still being referenced.], SQL: delete from job__step_execution where step_execution_id=?
It seems the CascadeType.ALL is getting ignored, since the StepExecutionContexts referencing the StepExecutions are not getting deleted and consequently the deletion of the StepExecutions fails.
I’ve read the migration guide but I can’t see that one of the changes mentioned there would cause this.
Does anybody happen to know what I am missing here?