【发布时间】:2013-05-11 09:10:36
【问题描述】:
我已经为此绞尽脑汁好几个小时了。我有两个模型:
@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.findById(1).address.street 抛出EntityNotFoundException: Bean has been deleted - lazy loading failed。不用说,数据库表不是空的。
有趣的是,Ebean.find(LocationAddress.class).findRowCount() 返回 3(这是正确的)。
有人知道可能是什么问题吗?谢谢。
【问题讨论】:
标签: java playframework playframework-2.1 ebean