Mantis - Resin
Viewing Issue Advanced Details
2048 major always 10-09-07 08:16 11-07-07 15:49
westrupp  
ferg  
normal  
closed 3.1.3  
no change required  
none    
none  
0002048: amber many-to-many cascade merge() does not delete children
        // begin transaction ...

        // child to be deleted
        int appId = 1;

        // parent
        int userId = 1;

        User user = em.find(User.class, userId);

        Collection apps = user.getApplications();



        Collection newApps = new ArrayList();

        for (Iterator iterator = apps.iterator(); iterator.hasNext();) {

            Application o = (Application) iterator.next();

            if (o.getAppId().intValue()!=appId){

                newApps.add(o);

            }

        }



        user.setApplications(newApps);

        em.merge(user);


        // ... commit transaction

        // child is not deleted

Notes
(0002461)
ferg   
11-07-07 15:49   
The merge operation does not automatically delete children, according to the JPA specification.