【问题标题】:JdbcMutableAclService + HSQLDB = BadSqlGrammarException when updating ACL更新 ACL 时 JdbcMutableAclService + HSQLDB = BadSqlGrammarException
【发布时间】:2013-01-16 10:00:51
【问题描述】:

我将 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

整个代码sn-p是:

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

【问题讨论】:

    标签: java spring spring-security hsqldb


    【解决方案1】:

    根据我的一般经验(老实说,我从未尝试过将 Spring ACL 与 HSQLDB 一起使用)并且根据 this,当 PreparedStatement 与 HSQLDB 一起使用时,必须添加批处理。因此,我猜你不能在 HSQLDB 上测试 Spring ACL。

    【讨论】:

      猜你喜欢
      • 2013-01-11
      • 1970-01-01
      • 2018-12-21
      • 2012-10-12
      • 1970-01-01
      • 2012-08-31
      • 1970-01-01
      • 1970-01-01
      • 2018-12-22
      相关资源
      最近更新 更多