I recently experienced a problem. The SelectOneMenu doesn't show the correct selected item, it just shows the blank when the Entity is a subclass of a MappedSupperclass.
1. If I change the ManyToOne mapping to EAGER fetch, it works fine.
2. If I change the Nr4Account class to not extends CodeTable class, and add the id property in itself, the SelectOneMenu will show the corrected item.
Does anybody have any idea why it happens? Thanks a lot.
Here is my Entity
@MappedSuperclass public abstract class CodeTable implements Serializable { private Long id; @Id @GeneratedValue @Column(name = "ID", unique = true, nullable = false) public Long getId() { ... } public void setId(Long id) { ... } }
@Entity @Table(name = "NR4_ACCOUNT") public class Nr4Account extends CodeTable { //Other properties .... }
public class NR4Slip { ... other properties private Nr4Account nr4Account; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name="NR4_ACCT_ID") public Nr4Account getNr4Account() { return this.nr4Account; } public void setNr4Account(Nr4Account nr4Account) { this.nr4Account = nr4Account; } }
Here is my page
<s:decorate id="Nr4AccountField" template="layout/edit.xhtml"> <ui:define name="label">Non-Resident Account Number</ui:define> <h:selectOneMenu id="Nr4Account" value="#{NR4SlipHome.instance.nr4Account}"> <s:selectItems value="#{codeTableManager.allNr4Accounts}" var="item" label="#{item.description}" noSelectionLabel="" /> <s:convertEntity /> </h:selectOneMenu> </s:decorate>