We're updating the issue view to help you get more done. 

Constraint violation when deleting entites in bi-directional, lazy OneToMany association with bytecode enhancement

Description

Given the association below, deleting all entities on both sides of the lazy association fails with a constraint violation if (and only if) bytecode enhancement is enabled (e.g. <enableLazyInitialization>true</enableLazyInitialization> using the hibernate-enhance-maven-plugin).

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 @Entity public class Employee { @Id private String name; @OneToMany(mappedBy = "employee", fetch=FetchType.LAZY) @LazyGroup("Tasks") private List<Task> tasks; ... } @Entity public class Task { @Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "ID_GENERATOR") @SequenceGenerator(name = "ID_GENERATOR", sequenceName = "TASK_SEQ", initialValue= 1, allocationSize = 1) private long id; @ManyToOne(fetch=FetchType.LAZY) @LazyToOne(LazyToOneOption.NO_PROXY) @LazyGroup("EmployeeForTask") @JoinColumn(name="emp_name") private Employee employee; ... }

Test code:

1 2 3 4 5 6 7 8 9 10 11 entityManager.clear(); transaction.begin(); { Employee e = entityManager.createQuery("from Employee e", Employee.class).getSingleResult(); entityManager.remove(e); // NOTE: if deleted after the tasks, the scenario does not fail for (Task t : e.getTasks()) { entityManager.remove(t); } } transaction.commit();

Environment

None

Status

Assignee

Gail Badner

Reporter

Stephen Fikes

Fix versions

Affects versions

5.4.1
5.3.7

Priority

Major