Hi,
I'm aware of Bug
https://hibernate.atlassian.net/browse/HHH-11585, which might be related and that was fixed in Hibernate 5.2.10. However, since upgrading to 5.2.10 from a 4.x project, I have trouble persisting entities with
order-inserts enabled for batch-inserts. The insert-order is not correct.
Again: this worked like a charm with Hibernate 4.x
The entities:
Code:
@Entity
@Table(name = "LM_LIMITE")
public class LimitEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_LM_LIMITE")
@SequenceGenerator(name = "SEQ_LM_LIMITE", sequenceName = "SEQ_LM_LIMITE", allocationSize = 1)
@Column(name = "LIMIT_ID")
private Long limitId;
...
}
and
Code:
@Entity
@Table(name = "LM_LIMIT_VERSIONEN")
public class LimitVersionEntity {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "SEQ_LM_LIMIT_VERSIONEN")
@SequenceGenerator(name = "SEQ_LM_LIMIT_VERSIONEN", sequenceName = "SEQ_LM_LIMIT_VERSIONEN", allocationSize = 1)
@Column(name = "EG_LIMIT_VERSION_ID")
private Long id;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "EG_LIMIT_ID")
private LimitEntity limitEntity;
...
}
In my code, I do something like this
in a loop:
Code:
LimitEntity limit = new LimitEntity();
...
LimitVersionEntity version = new LimitVersionEntity();
version.setLimitEntity(limit);
...
entityManager.persist(limit);
entityManager.persist(version);
With
order_inserts active, Hibernate now inserts the LimitVersionEntities before the LimitEntities. This leads to ConstraintViolations, as the foreign key constraint from table LM_LIMIT_VERSIONEN to LM_LIMITE cannot be fulfilled. With
order_inserts deactivated, it works again, as well as if I flush immediately after persisting the LimitEntity.
I'm assuming this to be a bug, as it worked before. Can anyone confirm or give any advise?
Thank you!