私は持って@Entity
います:
@Entity
public class Issue implements Serializable
{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
protected long id;
@ManyToOne
private IssueScope scope;
//getter/setter
}
カスタムを使用して、f:selectItemsIssueScopeConverter
を直接使用します。コンバーターは単純にIssueScope
- メソッドのIDを返します
getAsString
IssueScope
新しく作成されたオブジェクト( IDが設定された) を返すgetAsObject
これは、 p:selectOneMenuおよび次のようなコードを持つ同様のコンポーネントで問題を引き起こしません (以前は で何度も使用されていました@ManyToOne
) 。
<h:form id="fScope">
<p:selectOneButton rendered="true" value="#{issueBean.issue.scope}"
converter="IssueScopeConverter">
<f:selectItems value="#{issueBean.issueScopes}" var="s"
itemLabel="#{s.name}" itemValue="#{s}"/>
</p:selectOneButton>
<p:commandButton value="Save" actionListener="#{issueBean.save()}"/>
</h:form>
ここで、私の問題について説明しましょう: 実際、 は必要ありません。 からへの関係@ManyToOne
が必要です。@ManyToMany
Issue
IssueScope
@ManyToMany(fetch=FetchType.EAGER)
private List<IssueScope> scopes;
XHTML は次のように変更されます。
<h:form id="fScopes">
<p:selectManyCheckbox value="#{issueBean.issue.scopes}"
converter="ErpIssueScopeConverter">
<f:selectItems value="#{issueBean.issueScopes}" var="s"
itemLabel="#{s.name}" itemValue="#{s}"/>
</p:selectManyCheckbox>
<p:commandButton value="Save" actionListener="#{issueBean.save()}"/>
</h:form>
新しく作成して [保存Issue
] ボタンを押してエンティティを永続化すると、これは例外なく行われます。選択されたものも保持されます。次に、エンティティを更新する場合は、ボタンを押した後に取得します。IssueScopes
failed to lazily initialize a collection, no session or session was closed: org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
public void save()
私のメソッド@Named @ViewScoped IssueBean
は決して入力されません。
この問題は、JSF コンバーター (コレクションを参照) を使用する際の遅延読み込み例外に関連しているようですが、Seam 永続性を使用していないか、特別な種類の TransactionInterceptor` を持っていません。