4 Replies Latest reply on May 15, 2008 4:34 PM by Guillaume Jeudy

    entityConverter and java.lang.IllegalArgumentException: Not an entity class

    Guillaume Jeudy Master

      Hi,


      I am encountering a problem since I switched from JPA entity annotations to hibernate HBM mapping files. I'm using seam 2.0.1.GA.


      When I use convertEntity tag (value expression refDomainsAsList corresponds to a list of JPA ReferenceDomain entities mapped with HBM files):


      <h:selectOneRadio
      
                               value="#{domRelateInstancesAction.selectedFromDomain}">
      
                               <s:selectItems value="#{activeDomain.refDomainsAsList}"
      
                                    var="refDom" label="#{refDom.domainName}" />
      
                               <s:convertEntity />
      
                               <a4j:support
      
                                    action="#{domRelateInstancesAction.findRelatedFromInstances}"
      
                                    reRender="fromRel, toRel" event="onclick" />
      
                          </h:selectOneRadio>



      I get the below error:


      
      SEVERE: Error Rendering View[/editDomainInstanceFilRels.xhtml]
      
      java.lang.IllegalArgumentException: Not an entity class: com.archinsurance.rdm.entity.reference.impl.ReferenceDomainImpl
      
           at org.jboss.seam.Entity.forClass(Entity.java:208)
      
           at org.jboss.seam.persistence.PersistenceProvider.getId(PersistenceProvider.java:64)
      
           at org.jboss.seam.persistence.HibernatePersistenceProvider.getId(HibernatePersistenceProvider.java:167)
      
           at org.jboss.seam.framework.EntityIdentifier.<init>(EntityIdentifier.java:13)
      
           at org.jboss.seam.ui.converter.entityConverter.EntityLoader.createIdentifier(EntityLoader.java:40)
      
           at org.jboss.seam.ui.converter.entityConverter.AbstractEntityLoader.put(AbstractEntityLoader.java:50)
      
           at sun.reflect.GeneratedMethodAccessor2721.invoke(Unknown Source)
      
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      
           at java.lang.reflect.Method.invoke(Method.java:585)
      
           at org.jboss.seam.util.Reflections.invoke(Reflections.java:21)
      
           at org.jboss.seam.intercept.RootInvocationContext.proceed(RootInvocationContext.java:31)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:56)
      
           at org.jboss.seam.transaction.RollbackInterceptor.aroundInvoke(RollbackInterceptor.java:31)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.transaction.TransactionInterceptor$1.work(TransactionInterceptor.java:38)
      
           at org.jboss.seam.util.Work.workInTransaction(Work.java:40)
      
           at org.jboss.seam.transaction.TransactionInterceptor.aroundInvoke(TransactionInterceptor.java:32)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.core.MethodContextInterceptor.aroundInvoke(MethodContextInterceptor.java:42)
      
           at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:68)
      
           at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:107)
      
           at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:166)
      
           at org.jboss.seam.intercept.JavaBeanInterceptor.invoke(JavaBeanInterceptor.java:102)
      
           at org.jboss.seam.ui.converter.entityConverter.EntityLoader_$$_javassist_3.put(EntityLoader_$$_javassist_3.java)
      
           at org.jboss.seam.ui.converter.EntityConverter.getAsString(EntityConverter.java:77)
      
           at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.getFormattedValue(HtmlBasicRenderer.java:469)
      
           at com.sun.faces.renderkit.html_basic.RadioRenderer.renderOption(RadioRenderer.java:117)
      
           at com.sun.faces.renderkit.html_basic.SelectManyCheckboxListRenderer.encodeEnd(SelectManyCheckboxListRenderer.java:146)
      
           at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:836)
      
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:896)
      
           at javax.faces.render.Renderer.encodeChildren(Renderer.java:137)
      
           at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:812)
      
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:886)
      
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
      
           at javax.faces.component.UIComponent.encodeAll(UIComponent.java:892)
      
           at com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:592)
      
           at org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:108)
      
           at org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:189)
      
           at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
      
           at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
      
           at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
      
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
      
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
      
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
      
           at org.jboss.seam.debug.hot.HotDeployFilter.doFilter(HotDeployFilter.java:68)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:85)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:147)
      
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:276)
      
           at org.ajax4jsf.Filter.doFilter(Filter.java:175)
      
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:60)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.web.LoggingFilter.doFilter(LoggingFilter.java:58)
      
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
      
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
      
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      
           at jcifs.http.NtlmHttpFilter.doFilter(NtlmHttpFilter.java:118)
      
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
      
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
      
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:179)
      
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:84)
      
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
      
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      
           at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:157)
      
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:262)
      
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
      
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
      
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:446)
      
           at java.lang.Thread.run(Thread.java:595)




      Should s:convertEntity work on JPA entities regardless of the mapping technique being used ?


      I cannot use convertEntity without having to move back using @Entity and @Id annotations.


      Thanks,
      -Guillaume

        • 1. Re: entityConverter and java.lang.IllegalArgumentException: Not an entity class
          Pete Muir Master

          You can only use the entity converter with already persisted objects (Hibernate has thrown a TransientObjectException when asking for the ID of the entity).

          • 2. Re: entityConverter and java.lang.IllegalArgumentException: Not an entity class
            Guillaume Jeudy Master

            I am positive that this exact same usecase doesn't result in:


            java.lang.IllegalArgumentException: Not an entity class: com.archinsurance.rdm.entity.reference.impl.ReferenceDomainImpl



            when I map the entity using JPA annotations. (more specifically using the @Id annotation).


            I think the reason why is the fallback method fails in HibernatePersistenceProvider line 167:


            
            catch (TransientObjectException e) {
            
                return super.getId(bean, entityManager);
            
            }
            
            



            Now as to why the TransientObjectException was thrown: it is misleading in this case since I know my entities are in a detached state, not transient.


            Ideally the fallback method would work with entities mapped using a different technique than JPA annotations.


            Is there any reasons why s:convertEntity should not work with entities in a detached state ?


            • 3. Re: entityConverter and java.lang.IllegalArgumentException: Not an entity class
              Pete Muir Master

              Guillaume Jeudy wrote on May 15, 2008 03:21 PM:


              I am positive that this exact same usecase doesn't result in:

              java.lang.IllegalArgumentException: Not an entity class: com.archinsurance.rdm.entity.reference.impl.ReferenceDomainImpl



              when I map the entity using JPA annotations. (more specifically using the @Id annotation).



              That's perfectly possible - remember we can locate the identifier of a annotated entity based solely on the class definition, which we can't do on xml mapped entity.



              I think the reason why is the fallback method fails in HibernatePersistenceProvider line 167:

              catch (TransientObjectException e) {
                  return super.getId(bean, entityManager);
              }
              



              Now as to why the TransientObjectException was thrown: it is misleading in this case since I know my entities are in a detached state, not transient.

              Well, you need to take that up on the Hibernate forum.



              Ideally the fallback method would work with entities mapped using a different technique than JPA annotations.

              Is there any reasons why s:convertEntity should not work with entities in a detached state ?

              Err, you've just explained why it doesn't work. If you can come up with a better way of establishing the ID of a xml mapped entity, please create a JIRA issue with attached patch.

              • 4. Re: entityConverter and java.lang.IllegalArgumentException: Not an entity class
                Guillaume Jeudy Master

                As always thanks for your input Pete,


                Unfortunately I dont have as much time to spend on this, I will instead fallback on a custom converter to achieve my ends.


                I dont know how many Seam users are using JPA annotations but if there are many people using XML like me it would definitely be a plus if the seam framework could be improved to handle this case.


                Per hibernate doc it is possible to get the metadata of mappings from the SessionFactory. I suggest to have this alternative when looking up metadata if the persistence provider is hibernate.



                ClassMetaData metaData = factory.getClassMetaData(persistentClass);
                
                Serializable id = metaData.getIdentifier(Object entity, EntityMode entityMode);
                
                
                String identiferPropertyName = metaData.getIdentifierPropertyName();
                
                



                With the later option then you can call reflexively the identifier method getter on your entity instance.


                I dont know how easy it would be to integrate this in a patch however, if I have time and decide to patch locally I will surely post a JIRA.


                Regards,