我正在尝试使用 grails mongo 插件在 mongodb 中持久化 spring-security-acl 域对象。在执行以下代码行时
aclUtilService.addPermission Phone.class, phoneInstance.id, new PrincipalSid(username), BasePermission.ADMINISTRATION
我收到以下错误:
String-based queries like [executeQuery] are currently not supported in this implementation of GORM. Use criteria instead.. Stacktrace follows:
Message: String-based queries like [executeQuery] are currently not supported in this implementation of GORM. Use criteria instead.
有什么困难吗?
Grails 配置详情:
app.grails.version=2.0.3
app.name=eateri
app.servlet.version=2.5
app.version=0.1
plugins.mongodb=1.0.0.RC5
plugins.spring-security-acl=1.1
plugins.spring-security-core=1.2.7.2
最佳答案
正如@sudhir 提到的,aclService 中有一些方法使用 hql executeQuery 方法,例如:
protected AclObjectIdentity retrieveObjectIdentity(ObjectIdentity oid) {
return AclObjectIdentity.executeQuery(
"FROM AclObjectIdentity " +
"WHERE aclClass.className = :className " +
" AND objectId = :objectId",
[className: oid.type,
objectId: oid.identifier])[0]
}
但是mongodb gorm插件不支持hql,所以你的代码陷入hql错误的调用路径是这样的:
aclUtilService.addPermission -> aclService.createAcl -> retrieveObjectIdentity
还有另外两个使用 hql 的 aclService 方法:
deleteEntries, findChildren
因此,一个简单的解决方案是将 ACL 对象存储在 mysql 和 enable hibernate working with mongodb gorm 中。 .
另一个是用 meta programming 覆盖这 3 个 aclService 方法.
关于security - GORM 的这个实现目前不支持基于字符串的查询,如 [executeQuery],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11183643/