我有一个 Hibernate Query 返回的对象,该对象应该有一个替换列表。所以,我有一个“订单”对象,其中应该有一个“替换”设置,问题是当我查找该列表时,这就是我得到com.sun.jdi.InvocationException occurred invoking method.
的,然后,当代码继续运行并且我尝试访问该设置时,这就是我得到的failed to lazily initialize a collection of role: uo.ri.model.Order.ReplacementList, no session or session was closed
我真的不知道为什么会出现这个错误,我将在这里粘贴我Order
和我的Replacement
课程,希望你能解决它
@Entity
@Table(name = "TOrder")
public class Order implements Serializable {
@Id
@GeneratedValue
long id;
@Temporal(TemporalType.DATE)
private Date creation_date;
@Temporal(TemporalType.DATE)
private Date reception_date;
@Enumerated(EnumType.STRING)
private PedidoStatus status;
private float price;
@OneToMany(mappedBy = "order")
private Set<PedidoRepuesto> replacementList= new HashSet<PedidoRepuesto>();
@ManyToOne
private Proveedor provider;
}
@Entity
@Table(name = "TReplacement")
public class Repuesto implements Serializable {
@Id
@GeneratedValue
long id;
private String name;
private double price;
private int having;
private int likeToHave;
private int minimumToHave;
private int totalHaving;
private float totalPrice;
@OneToMany(mappedBy = "replacement")
private Set<OrderReplacement> orderReplacements= new HashSet<OrderReplacement>();
@OneToMany(mappedBy = "replacement")
private Set<Sustitucion> sustituciones = new HashSet<Sustitucion>();
@OneToMany(mappedBy = "replacement")
private Set<ProviderReplacement> providerReplacement= new HashSet<ProviderReplacement>();
}
两个类都有 getter/setter 和构造函数。
如果您需要我在此处粘贴更多类或其他内容,请询问。太感谢了。