Details
Assignee
UnassignedUnassignedReporter
Aurelien DROUARDAurelien DROUARDComponents
Priority
Major
Details
Details
Assignee
Unassigned
UnassignedReporter
Aurelien DROUARD
Aurelien DROUARDComponents
Priority
Created October 9, 2013 at 7:41 AM
Updated May 30, 2014 at 3:26 PM
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=aram_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"