2013-01-16 22 views
0

我使用Spring ACL和MySQL一起工作正常。然而,當集成測試我使用HSQLDB引擎,當我打電話aclService.updateAcl(myAcl)它拋出以下異常(S):更新ACL時JdbcMutableAclService + HSQLDB = BadSqlGrammarException

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上一切正常。

Spring 3.1.2.RELEASE。

編輯: 其實異常被拋出只有當acl.getEntries()返回空列表(ACL中剛剛創造的 - 它不包含任何的ACE)。我通過擴展JdbcMutableAclService的默認實現並通過在空列表上調用createEntries()來覆蓋導致此問題的updateAcl()方法來解決此問題。我仍然不知道這個問題的真正原因,但我設法讓它工作。這裏是我快速的解決方案:

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

回答

0

在我的一般經驗(老實說,我從來沒有嘗試過春季ACL與HSQLDB),並根據this時的PreparedStatement與HSQLDB使用的它是強制性的增加一批。因此,我猜你不能在HSQLDB上測試Spring ACL。