5

使用 Play Framework,我有一个这样的模型:

class MyModel extends Model {
    // Some columns

    @ManyToOne
    public OtherModel other;

    public OtherModel getOther() {
        return other;
    }
}

由于我无法理解的原因,如果我调用myModel.otherOR myModel.getOther()myModel作为 的实例MyModel),我得到一个 Null 值,即使它应该返回 OtherModel 的实例!

此外,如果我将getOther()方法更改为此:

public OtherModel getOther() {
    console.log (String.valueOf(other));
    return other;
}

getOther()返回预期的实例OtherModel

为什么我会得到这个,以及如何解决这个奇怪的行为?

4

1 回答 1

5

我有一个类似的问题(但我不需要console.log声明)。

我所做的只是用私有字段替换公共字段,并使用公共 getter 和 setter。我认为这是一个 Playframework 错误,但我找不到我在哪里看到的。

于 2012-10-22T19:58:24.097 回答