0

私は持って@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が必要です。@ManyToManyIssueIssueScope

@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] ボタンを押してエンティティを永続化すると、これは例外なく行われます。選択されたものも保持されます。次に、エンティティを更新する場合は、ボタンを押した後に取得します。IssueScopesfailed 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` を持っていません。

4

1 に答える 1

1

http://www.simtay.com/simple-crud-web-application-with-jsf-2-1-primefaces-3-5-maven-and-jpa/をご覧ください

それが役立つかどうかを確認してください。

よろしくお願いします

于 2013-03-22T16:46:01.760 に答える