我将 Spring ACL 与 MySQL 一起使用,它工作正常。但是,当我在集成测试中使用 HSQLDB 引擎时,当我调用aclService.updateAcl(myAcl)
它时会引发以下异常:
Caused by: org.springframework.jdbc.BadSqlGrammarException:
PreparedStatementCallback; bad SQL grammar
[insert into acl_entry (acl_object_identity, ace_order, sid, mask, granting,
audit_success, audit_failure)values (?, ?, ?, ?, ?, ?, ?)]; nested exception is
java.sql.SQLException: statement is not in batch mode
...
java.sql.SQLException: statement is not in batch mode
...
org.hsqldb.HsqlException: statement is not in batch mode
整个代码片段是:
ObjectIdentity oi = new ObjectIdentityImpl(domainObject);
MutableAcl acl = aclService.createAcl(oi);
acl.setOwner(new PrincipalSid(SYSTEM_PRINCIPAL_SID));
if (parentObject != null) {
Acl parent = aclService.readAclById(new ObjectIdentityImpl(parentObject));
acl.setParent(parent);
}
aclService.updateAcl(acl);
该aclService
字段是类的实例JdbcMutableAclService
。请注意,在 MySQL 上一切正常。
春季 3.1.2.RELEASE。
编辑:
实际上只有在acl.getEntries()
返回空列表时才会引发异常(因为刚刚创建了 ACL - 它不包含 ACE)。我通过扩展默认实现并通过调用空列表JdbcMutableAclService
覆盖updateAcl()
导致问题的方法来解决问题。createEntries()
我仍然不知道这个问题的真正原因,但我设法让它工作。这是我的快速解决方案:
@Override
public MutableAcl updateAcl(MutableAcl acl) throws NotFoundException {
if (acl.getEntries().size() > 0) {
return super.updateAcl(acl);
}
Assert.notNull(acl.getId(), "Object Identity doesn't provide an identifier");
// Change the mutable columns in acl_object_identity
updateObjectIdentity(acl);
// Retrieve the ACL via superclass (ensures cache registration, proper retrieval etc)
return (MutableAcl)super.readAclById(acl.getObjectIdentity());
}