我的表格:
商品: id, 名称
优惠: id, 价值, 商品id
实体:
@Entity
@Table(name="product")
public class Product implements Serializable {
@OneToMany(mappedBy="product")
private Set<Offer> offers;
...
}
@Entity
@Table(name="offer")
public class Offer implements Serializable {
@ManyToOne
@JoinColumn(name="PRODUCT_ID")
private Product product;
...
}
当我尝试从表Product
获取一些数据时,我会得到一个java.lang.NullPointerException
错误,并且这段代码:product.getOffers()
返回:
{IndirectSet: not instantiated}
如何解决这个问题?