本文介绍了为什么Ebean无缘无故地返回null?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Play框架,我有一个像这样的模型:

Using Play Framework, I have a model like this :

class MyModel extends Model {
    // Some columns

    @ManyToOne
    public OtherModel other;

    public OtherModel getOther() {
        return other;
    }
}

由于某种原因我无法理解,如果我调用myModel.othermyModel.getOther()(myModelMyModel的实例),即使得到的值应该返回OtherModel的实例,我也会得到一个Null值!

For a reason I can't understand, if I call myModel.other OR myModel.getOther() (myModel being an instance of MyModel), I got a Null value, even if it should return an instance of OtherModel !

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

Moreover, if I change the getOther() methods to this :

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

getOther()返回预期的OtherModel

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

Why do I get this, and how to fix this odd behavior?

推荐答案

我遇到了类似的问题(但我不需要console.log语句).

I had a similar problem (but I did not need the console.log statement).

我所做的只是将公共领域替换为私人领域,并使用公共吸气剂&二传手.我认为这是一个Playframework错误,但我找不到我看到的地方.

All I did was just replacing public fields by private ones, and using public getters & setters. I think it was a Playframework bug, but I don't find where I saw that.

这篇关于为什么Ebean无缘无故地返回null?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-11 14:08