钩子导致使用子查询插入问题

时间:2016-06-17 13:11:57

标签: orientdb

我不确定为什么这会导致我出现问题,但我使用的是Orient 2.1.19,也在2.1.12中找到了。我们正在构建一些钩子来实现加密方法。我知道2.2实现了一些加密,但我们有一些进一步的要求。

无论如何,我们有onRecordAfterRead,onRecordBeforeCreate和onRecordBeforeUpdate的钩子。它适用于大多数语句,但是在使用钩子的情况下,运行使用插入中的子查询设置链接属性的查询失败。这是一个示例查询:

create EDGE eThisEdge from (select from vVertex where thisproperty = 'this') to (select from vVertex where thatProperty = 'that' ) set current = (select from lookupCurrent where displayCurrentPast = 'Current');

运行此查询会出现错误:

com.orientechnologies.orient.core.exception.OValidationException:字段&#39.eThisEdge.current'已被声明为LINK,但该值不是记录或记录ID。

在插入过程中运行子查询的方式存在一些问题,因为如果我在没有设置任何属性的情况下运行插入,那么运行更新来设置属性,这是有效的。我不想为我们的基础数据和编码重写所有插入内容,只是为了解决这个问题,似乎我在这里错过了一些东西。

有没有人看过钩子的这种问题?

最大的问题似乎是围绕onRecordBeforeCreate代码。我们正在尝试使用通用挂钩来加密数据库中的字符串。这是onRecordBeforeCreate方法的基础知识:

    public RESULT onRecordBeforeCreate( ODocument oDocument) {

    RESULT changed = RESULT.RECORD_NOT_CHANGED;
    try {
        if(classIsCipherable(oDocument)) {
            for (String field : oDocument.fieldNames()) {
                if (oDocument.fieldType(field) != null && oDocument.fieldType(field) == OType.STRING && oDocument.field(field) != null) {
                    oDocument.field(field, crypto.encrypt(oDocument.field(field).toString()));
                    changed = RESULT.RECORD_CHANGED;
                }
            }
        }
        return changed;
    } catch (Exception e) {
        throw new RuntimeException( e );
    }

有什么东西看起来很明显,我在运行创建边缘语句时遇到问题,该语句使用属性作为链接来设置属性吗?

1 个答案:

答案 0 :(得分:1)

查询select from lookupCurrent where displayCurrentPast = "Current"返回多个元素,必须使用LinkList或LinkSet