如何实现Spring Roo实体的“全部删除”?
|
我正在尝试删除Spring Roo实体的所有数据库条目。当我查看“ 0”时,似乎没有“全部删除”方法。我尝试自己实现它(ѭ1是Roo实体的名称。不要介意命名。它是通过数据库进行reverese设计的,以后可能会更改):
public static int Licences.deleteAll() {
return entityManager().createQuery(\"delete from Licences o\").executeUpdate();
}
它可以正常编译,但是当我调用Licences.deleteAll()
时,出现以下异常:
org.springframework.dao.InvalidDataAccessApiUsageException: Executing an update/delete query;
nested exception is javax.persistence.TransactionRequiredException: Executing an update/delete query (NativeException)
加ѭ5没什么区别。
我在这里想念什么?
这种方法是完全错误的,我需要这样实现吗:
public static void Licences.deleteAll() {
for (Licences licence : findAllLicenceses()) {
licence.remove();
}
}
这是可行的,但是JPA是否足够聪明,可以将其转换为delete from licences
查询,还是会创建n
查询?
没有找到相关结果
已邀请:
3 个回复
皇小福另届
至
https://jira.springsource.org/browse/SPR-5999 再见
佃蒜狗掂哥
貉骂