Uploaded image for project: 'Hibernate ORM'
  1. HHH-13241

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

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      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).

      @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:

                              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();
      

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: