这不是一个新的例外。我在堆栈溢出中浏览了很多论坛帖子,并了解为什么会发生这种情况。但我需要帮助来解决我的问题。
我有两个实体豆设备类和设备。以下是代码。
public class EquipmentClass implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "class_name")
private String className;
@Column(name = "description")
private String description;
@OneToMany(cascade = CascadeType.ALL, mappedBy = "equipmentClass")
private Collection<Equipment> equipmentCollection;
// getter and setter methods
}
public class Equipment implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Basic(optional = false)
@Column(name = "id")
private Integer id;
@Basic(optional = false)
@Column(name = "created_on")
@Temporal(TemporalType.TIMESTAMP)
private Date createdOn;
@Basic(optional = false)
@Column(name = "updated_on")
@Temporal(TemporalType.TIMESTAMP)
private Date updatedOn;
@JoinColumn(name = "equipment_class", referencedColumnName = "id")
@ManyToOne(optional = false)
private EquipmentClass equipmentClass;
// setter and getter methods
}
在添加设备期间,我设置了设备类并使用equipmentFacade.create(equipment);
(持久化实体)将其持久化
EquipmentClass ec = equipment.getEquipmentClass();
>>> ec.getEquipmentCollection().add(equipment); <<
equipmentClassFacade.edit(ec);
我在上面标记的 ( >> < ) 行中遇到异常。
正如这里所解释的,我试着去做ec.getEquipmentCollection().size();
。但我有例外。
我应该如何进行?任何帮助深表感谢。