这不是一个新的异常(exception)。我在堆栈溢出中浏览了很多论坛帖子,并了解为什么会发生这种情况。但我需要帮助来解决我的问题。我有两个实体 bean 设备类和设备。以下是代码。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);我在上面标记的 ( >> 正如 here 所解释的,我尝试做 ec.getEquipmentCollection().size(); 。但我在那里得到了异常(exception)。我应该如何进行?任何帮助深表感谢。 最佳答案 我想如果您在检索 equipment.getEquipmentClass().getEquipmentCollection().size() 实例后添加 equipment 它将解决您的问题。事实可能是在您调用 getEquipmentCollection() 的地方无法再访问持久性上下文,但我需要有关您的上下文的其他信息来帮助您(ejb、事务上下文等)。你能在抛出异常的地方访问 entityManager 实例吗?关于java - EJB 异常 - 尝试使用具有空 session 的间接来遍历关系。,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/15680490/
10-12 00:36
查看更多