users@glassfish.java.net

Re: manytomany cascade delete

From: Felipe Gaúcho <fgaucho_at_gmail.com>
Date: Sun, 10 May 2009 20:43:10 +0200

solved.. I just learned we need to handle the bulk delete operations
by ourselves, JPA do not cascade the delete to the relationships....

        @Override
        public void delete(long id) throws IllegalStateException,
                        IllegalArgumentException, TransactionRequiredException,
                        PersistenceException {
                Query query = manager
                                .createNamedQuery(FpCertificate.BULK_DELETE_CERTIFICATES);
                query.setParameter(FpCertificate.USER_ID_PARAM, new Long(id));
                query.executeUpdate();
                FpUser user = manager.find(FpUser.class, new Long(id));
                manager.remove(user);
        }