NetBeans « Delete « JPA Q&A





1. JPA: How can I delete an object in collections?    forums.netbeans.org

Hi, I'm going crazy with this. I know that for delete an object directly from de database I can use: entityManager.remove(myEntityObj); But, I need to delete an object from a collection child retrieved from a jpa entity. What I'm doing is this: ... MyParentEntity myParentEntity = entityManager.find(MyParentEntity.class, id); myParentEntity.getChildEntityCollection().remove(myChildEntity); ... begin(); entityManager.merge(myEntity) ...commit(); ... After commit, the child object is apperently ...

3. Re: JPA: How can I delete an object in collections?    forums.netbeans.org

For now, I have set a auxiliary collection of object that will be deleted when the user submmit the changes :s ; but I would like to delete this child objects automatically just deleting them from the parents collection (and not use this aux. collection). I will try removing it from the collection and setting to 'null' the reference field.