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

Bulk delete doesn't cascade delete on join table

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 4.2.5
    • Fix Version/s: 4.2.6, 4.3.0.Beta5
    • Component/s: hibernate-core
    • Labels:
      None
    • Environment:
      Hibernate 4.2.5.Final, Firebird, Tomcat 7, jdk 1.7, Windows 7
    • Last commented by a user?:
      true

      Description

      HQL delete doesn't cascade delete on join table.

      Person bob = new Person();
      bob.setId(1l);
      bob.setFirstname("bob");
      getCurrentSession().save(bob);

      Cat felix = new Cat();
      felix.setId(1l);
      felix.setName("felix");
      Set<Person> owners = new HashSet<Person>();
      owners.add(bob);
      felix.setOwners(owners);
      getCurrentSession().save(felix);

      Query query = getCurrentSession().createQuery("delete com.company.product.domain.Cat c where c.id=:param_id)");
      query.setParameter("param_id", 1l);
      return query.executeUpdate();

      insert into PERSON (FIRSTNAME, ID) values (?, ?)
      insert into CAT (NAME, ID) values (?, ?)
      insert into CAT_PERSON (ID_CAT, ID_PERSON) values (?, ?)
      delete from CAT where ID=?

      -> ConstraintViolationException: could not execute statement
      violation of FOREIGN KEY constraint "FK_3QS4XQHEUL1KIQILV53S1F0GB" on table "CAT_PERSON"

      Note that if Cat extends Animal with joined-subclass mapping everything is OK.

        Attachments

        1. Cat.hbm.xml
          0.7 kB
        2. Cat.java
          0.6 kB
        3. Person.hbm.xml
          0.5 kB
        4. Person.java
          0.4 kB

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved: