[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Cascade Delete

javacory do-not-reply at jboss.com
Thu Dec 27 13:58:23 EST 2007


I'm trying to delete a child object in a @OneToMany relationship and the persistence manager is not removing the child from the database.

The @OneToMany side is mapped as such:
@OneToMany(cascade=CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "parent")

The child is mapped as such:
@ManyToOne
@JoinColumn(name = "PARENT_ID")

The code I'm using to do this is (em is the EntityManager):
Query query = em.createQuery( "... " );
Parent parent = (RawDaar) query.getSingleResult();
parent.getChildren().remove(0);

em.persist( parent );

I noticed the child delete SQL is not generated and when I find the parent back ( after an em.flush() & em.clear() ), the child still exists.

If I do a em.remove( child ), that works, but I didn't think I needed that.

Environment:
EJB3
JBoss 4.2.0GA

Thanks much,

Cory.

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4115769#4115769

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4115769



More information about the jboss-user mailing list