Google App Engine - 删除JPQL查询和级联 [英] Google App Engine - DELETE JPQL Query and Cascading
问题描述
我注意到,在使用下面的JPQL查询时,PersistentUser的子项不会被删除。但是,如果我执行 entityManager.remove(object)
,则会删除子项。这是预期的吗?为什么下面的JPQL查询不会执行级联删除?
@OneToMany(mappedBy =persistentUser,cascade = CascadeType .ALL)
私人收藏< 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();
}
删除操作不会级联。根据JPA 1.0规范:
lockquote
4.10批量更新和删除操作
( ...)
删除操作仅适用于指定类的
实体和
的子类。 不会将
级联到相关实体。
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();
}
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.
这篇关于Google App Engine - 删除JPQL查询和级联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!