Java Play Framework 2.1和Ebean:model Finder不返回任何数据

Java Play Framework 2.1和Ebean:model Finder不返回任何数据,java,playframework,playframework-2.1,ebean,Java,Playframework,Playframework 2.1,Ebean,我已经为此绞尽脑汁好几个小时了。我有两种型号: @Entity @Table(name = "app_user") public class AppUser extends Model { @Id Long id; … @Constraints.Required @Valid @OneToOne(cascade = CascadeType.ALL, optional = false) public LocationAddress ad

我已经为此绞尽脑汁好几个小时了。我有两种型号:

@Entity
@Table(name = "app_user")
public class AppUser extends Model {

    @Id
    Long id;

    …

    @Constraints.Required
    @Valid
    @OneToOne(cascade = CascadeType.ALL, optional = false)
    public LocationAddress address;

    @Valid
    @OneToOne(cascade = CascadeType.ALL, optional = true)
    public LocationAddress addressBilling;

    …

}

@Entity
@Table(name = "location_address")
public class LocationAddress extends Model {

    @Id
    Long id;

    @Constraints.Required
    @Constraints.MaxLength(TextSize.DEFAULT)
    @Column(length = TextSize.DEFAULT, nullable = false)
    public String street;

    @Constraints.MaxLength(TextSize.TINY)
    @Column(length = TextSize.TINY)
    public String streetNo;

    @ManyToOne(cascade = CascadeType.PERSIST, optional = false)
    public Country country;

    …

    @OneToOne(mappedBy = "address")
    public AppUser userAddress;

    @OneToOne(mappedBy = "addressBilling")
    public AppUser userAddressBilling;

    @OneToOne(mappedBy = "address")
    public AdvertisingLocation advertisingLocationAddress;

    // -- Queries

    public static Finder<Long, LocationAddress> find = new Finder<Long, LocationAddress>(Long.class, LocationAddress.class);

    public static List<LocationAddress> all() {
        return find.all();
    }

    public static LocationAddress findById(long id) {
        return find.byId(id);
    }

}
问题是LocationAddress.all不返回任何内容,因此AppUser.findById1.address.street抛出EntityNotFoundException:Bean已被删除-延迟加载失败。不用说,数据库表不是空的

有趣的是,Ebean.findLocationAddress.class.findRowCount返回3这是正确的


有人看到了什么问题吗?谢谢。

再过几个小时,我终于找到了问题的根源@LocationAddress中的OneToOne字段是不需要的,如果为null,则不会返回实体。

我曾多次遇到此问题。第1局也一样


我解决这个问题的方法是将字段设置为私有,并用getter/setter将其包装起来

我不明白答案。你是如何解决这个问题的?我也看到了同样的情况,如果它是一个双向关系,那么对于要返回的对象,关系的两边都不能为null,就像这里的情况一样。我将其更改为单向关系,因此即使其中一侧为null,也会返回对象。您从类中删除了所有@OneToOne字段,然后找到了find.allworked。我现在明白了。但在我看来,这需要更多的挖掘。在你的情况下,你不需要它们。其他人可能需要它们。你可以发布你的数据库,这样我就可以复制这个吗?