Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google App Engine - DELETE JPQL Query and Cascading

I noticed that the children of PersistentUser are not deleted when using the JPQL query below. However, the children are deleted if I perform an entityManager.remove(object). Is this expected? Why doesn't the JPQL query below also perform a cascaded delete?

@OneToMany(mappedBy = "persistentUser", cascade = CascadeType.ALL)
private Collection<PersistentLogin> persistentLogins;

...

@Override
@Transactional
public final void removeUserTokens(final String username) {
    final Query query = entityManager.createQuery(
        "DELETE FROM PersistentUser p WHERE username = :username");
    query.setParameter("username", username);
    query.executeUpdate();
}
like image 408
Taylor Leese Avatar asked Jun 08 '10 08:06

Taylor Leese


1 Answers

This is expected, the JPQL delete operation does not cascade. From the JPA 1.0 specification:

4.10 Bulk Update and Delete Operations

(...)

A delete operation only applies to entities of the specified class and its subclasses. It does not cascade to related entities.

like image 71
Pascal Thivent Avatar answered Sep 20 '22 18:09

Pascal Thivent