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

Delete an element doesn't delete automatically rows in table of a "map" mapping

    Details

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

      Description

      Delete an element doesn't delete automatically rows in table of a "map" mapping :

      --------------
      Java test :
      --------------
      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);

      felix.setMap(new HashMap<Integer, Integer>());
      felix.getMap().put(1, 10);
      felix.getMap().put(2, 10);
      felix.getMap().put(3, 15);
      felix.getMap().put(4, 20);

      getCurrentSession().save(felix);

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

      --------------
      Generated SQL:
      --------------
      insert into PERSON (FIRSTNAME, ID) values (?, ?)
      insert into CAT (NAME, ID) values (?, ?)
      insert into CAT_PERSON (ID_CAT, ID_PERSON) values (?, ?)
      insert into MAP (CAT_KEY, MAP_KEY, MAP_VALUE) values (?, ?, ?)
      insert into MAP (CAT_KEY, MAP_KEY, MAP_VALUE) values (?, ?, ?)
      insert into MAP (CAT_KEY, MAP_KEY, MAP_VALUE) values (?, ?, ?)
      insert into MAP (CAT_KEY, MAP_KEY, MAP_VALUE) values (?, ?, ?)
      delete from CAT_PERSON where (ID_CAT) in (select ID from CAT where ID=?)
      delete from CAT where ID=?

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

        Attachments

        1. Cat.hbm.xml
          0.9 kB
          Aurelien DROUARD
        2. Cat.java
          0.8 kB
          Aurelien DROUARD
        3. Person.hbm.xml
          0.5 kB
          Aurelien DROUARD
        4. Person.java
          0.4 kB
          Aurelien DROUARD

          Issue links

            Activity

              People

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

                Dates

                • Created:
                  Updated: