merge « Delete « JPA Q&A





1. Why won't JPA delete owned entities when the owner entity loses the reference to them?    stackoverflow.com

I've got a JPA entity "Request", that owns a List of Answers (also JPA entities). Here's how it's defined in Request.java:

@OneToMany(cascade= CascadeType.ALL, mappedBy="request")
private List<Answer> answerList;
And in Answer.java:
@JoinColumn(name = "request", referencedColumnName="id")
@ManyToOne(optional = ...

2. I cant figure out how to get merge to delete orphaned object    forum.hibernate.org

I have a parent class such as this: @Entity(name="parent") @Table(name = "PARENT") public class Parent { @OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY) @JoinColumn(name="PARENT_ID") @Cascade({org.hibernate.annotations.CascadeType.ALL}) private List children; } Then what I do in my application is I load a new instance of Parent from an XML message. I discover that an equivalent record of this Parent already exists (using secondary columns) ...

3. JPA merge with DELETE_ORPHAN    forum.hibernate.org

4. Session.merge and deleted Objects    forum.hibernate.org

What's the rationale for NOT throwing ObjectDeletedException (or StaleObjectException) when you pass an object with an identifier that was deleted in a previous transaction to Session.merge()? Just think about the usual CRUD interface: User 1 loads the object for modifications; User 2 deletes the object; User 1 saves the modifications (thru Session.merge). Now, instead of getting an exception, the object will ...

5. Can merge() re-create deleted objects?    forum.hibernate.org

Hi, I am using Hibernate3-3.2.0.dev-20060906, with annotations for mappings and I have the following issues: I create an object in one session and become persisted in the db. When the session is closed this object becomes a detached object. In a separate session I retrieve this object and delete it from db. In another fresh session, I call merge() on the ...

6. merge and all-delete-orphan    forum.hibernate.org

I have a parent class which has a Set of children, the cascade on the one-to-many association is "all-delete-orphan". When the set of children are changed and session.merge(parent) is called, it seems that Hibernate first insert new children and then deletes all children which are not in that set any longer. For example if Parent A has two children B and ...

7. Delete-Orphan on One-to-Many relationship -> Why merge?    forum.hibernate.org

Hello! I'm using Hibernate Annotation @Cascade(CascadeType.DELETE_ORPHAN) in addition to my JPA cascading annotations. If I try to save a detached instance of the parent object whose children have been modified/deleted, update() only sets the foreign key of the children to 'null'. Why are orphans only deleted when I use merge()?? Does this indicate that there might be a session that has ...