I have an @Entity with :
@Entity
public class Issue implements Serializable
{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY)
protected long id;
@ManyToOne
private IssueScope scope;
//getter/setter
}
I use the custom IssueScopeConverter to directly use the IssueScope with f:selectItems. The converter simply
- returns the id for the method
getAsString - return a newly created object
IssueScope(with id set) forgetAsObject
This does not raise any problems (and is used many times before with @ManyToOne) with p:selectOneMenu and similar components with code like this:
<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>
Now let's describe my problem: In fact I don't need a @ManyToOne, I need a @ManyToMany relationship from Issue to IssueScope:
@ManyToMany(fetch=FetchType.EAGER)
private List<IssueScope> scopes;
and the XHTML will change to this:
<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>
If I newly create Issue and then push the Save button to persist the entity this is done without exception. Even selected IssueScopes are persisted. Then, if I want to update the entity, I get a 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 after pushing the button.
The method public void save() in my @Named @ViewScoped IssueBean is never entered.
The problem seems to be related to Lazy loading exception when using JSF Converter (refering to a collection), but I don't use Seam persistence or have special kind of TransactionInterceptor`.