我用 Jboss forge 生成简单的 CRUD。没关系,但是当我获得我的实体 ( postesPrejudices
) 列表时,会添加一个空元素:
我的实体:
@ManyToMany
@JoinTable(name = "COR_TYPEFICHE_REGRPRJ",
joinColumns = {@JoinColumn(name = "ID_TYPEFICHE", referencedColumnName = "ID")},
inverseJoinColumns = @JoinColumn(name = "ID_REGRPRJ", referencedColumnName = "ID"))
@OrderColumn(name = "ORDRE")
private List<RegroupementPostePrejudice> postesPrejudices;
这是我的观点,我使用带有单元持久化的经典视图:
@Named
@Stateful
@ConversationScoped
public class TypeFicheBean implements Serializable {
...
@Inject
private Conversation conversation;
@PersistenceContext(unitName = "persistence-unit", type = PersistenceContextType.EXTENDED)
private EntityManager entityManager;
public void retrieve() {
if (FacesContext.getCurrentInstance().isPostback()) {
return;
}
if (this.conversation.isTransient()) {
this.conversation.begin();
this.conversation.setTimeout(1800000L);
}
if (this.id == null) {
this.typeFiche = this.example;
} else {
this.typeFiche = findById(getId());
}
}
public TypeFiche findById(Long id) {
return this.entityManager.find(TypeFiche.class, id);
}