[ 
https://issues.apache.org/jira/browse/MYFACES-3306?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Jakob Korherr resolved MYFACES-3306.
------------------------------------

    Resolution: Not A Problem

> <h:selectManyCheckBox> + JPA with Hibernate creates Hibernate 
> PersistentCollection where it should not. Causes 
> ---------------------------------------------------------------------------------------------------------------
>
>                 Key: MYFACES-3306
>                 URL: https://issues.apache.org/jira/browse/MYFACES-3306
>             Project: MyFaces Core
>          Issue Type: Bug
>          Components: General
>    Affects Versions: 2.1.2
>         Environment: JPA with Hibernate + Spring
>            Reporter: Kristian Jörg
>   Original Estimate: 24h
>  Remaining Estimate: 24h
>
> I have a case where I use a JPA domain object (Mission) that has a standard 
> @ManyToMany relationship to another domain object Departments. The fetch type 
> is set to EAGER on both ends.
> The web page has a <h:selectManyCheckBox> with all possible Departments. The 
> selection is then mapped to the mission object's department set via a custom 
> converter. This all works well.
> When I submit my form I get an org.hibernate.LazyInitializationException in 
> (I believe)  the validation phase. The problem is that MyFaces tries to 
> create a new instance of the specific hibernate class PersistentSet (which 
> should NOT be used outside Hibernate). It then populates this Set with 
> objects and that is when LazyInitializationException hits!
> I have pinpointed the exact location to 
> org.apache.myfaces.shared_impl.renderkit.SharedRendererUtils.java, Line 255:
>                            // try to create the (concrete) collection from 
> modelType 
>                             // or with the class object of componentValue (if 
> any)
>                             try
>                             {
>                                targetForConvertedValues = (componentValue != 
> null
>                                          ? componentValue.getClass()
>                                          : modelType).newInstance();
>                             }
> With I add a check so we are not instanciating Hibernate collections 
> (AbstractPersistentCollection) the program then goes on to create a standard 
> HashSet and all is well. My program works perfectly with this patch:
>                            // try to create the (concrete) collection from 
> modelType 
>                             // or with the class object of componentValue (if 
> any)
>                             try
>                             {
>                                targetForConvertedValues = (componentValue != 
> null && !(componentValue instanceof 
> org.hibernate.collection.AbstractPersistentCollection)
>                                          ? componentValue.getClass()
>                                          : modelType).newInstance();
>                             }
> Of course, adding a dependency on Hibernate in Myfaces is not the correct 
> solution, so another solution has to be invented. 
> My program is solid in itself with regards to the dreaded LIE exception, it 
> is only when I use persisted objects with OneToMany or ManyToMany collections 
> that this problem occurs. 
> MyFaces should never try to instanciate Hibernate collections without having 
> an entity manager session, which you do not.
> I can attach some code examples if needed, but the problem lies not in the 
> rather standard JSF code, but in this specific point in code listed above. 
> Let me know if more examples are needed.

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira


Reply via email to