Google App Engine - DELETE JPQL Query and Cascading

此生再无相见时 提交于 2019-12-21 10:53:13

问题


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();
}

回答1:


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.



来源:https://stackoverflow.com/questions/2995693/google-app-engine-delete-jpql-query-and-cascading

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!