1 Reply Latest reply on Oct 12, 2006 6:14 AM by Carsten Hoehne

    Problem with HibernateEntity when id is not of type String

    Carsten Hoehne Master

      Hello,
      i do have a little problem with the upgrade to HibernateEntity.
      a ClassCastException: java.lang.String is raised at org.hibernate.type.LongType.set(LongType.java:42)
      see below.

      My question: how must an id of type other than String be handled? The idclass seems to be gone.
      My configuration in components.xml:

       <factory name="bazProject" value="#{bazProjectHome.instance}"/>
       <component name="bazProjectHome" class="org.jboss.seam.framework.HibernateEntityHome">
       <property name="entityClass">de.bafz.lims.model.Project</property>
       <property name="session">#{bazDatabase}</property>
       <property name="id">#{bazProjectID}</property>
       </component>
       <factory name="bazExperiment" value="#{bazExperimentHome.instance}"/>
       <component name="bazExperimentHome" class="org.jboss.seam.framework.HibernateEntityHome">
       <property name="entityClass">de.bafz.lims.model.Experiment</property>
       <property name="session">#{bazDatabase}</property>
       <property name="id">#{bazExperimentID}</property>
       </component>
      
      

      bazProject works fine. bazExperiment raises the exception.

      This is the configuration i used for ManagedHibernateEntity(this was replaced by HibernateEntity)
       <component name="bazProject" class="org.jboss.seam.core.ManagedHibernateEntity">
       <property name="entityClass">de.bafz.lims.model.Project</property>
       <property name="session">#{bazDatabase}</property>
       <property name="id">#{bazProjectID}</property>
       <property name="idClass">java.lang.String</property>
       </component>
       <component name="bazExperiment" class="org.jboss.seam.core.ManagedHibernateEntity">
       <property name="entityClass">de.bafz.lims.model.Experiment</property>
       <property name="session">#{bazDatabase}</property>
       <property name="id">#{bazExperimentID}</property>
       <property name="idClass">java.lang.Long</property>
       </component>
      
      


      the end of the stacktrace:
      Caused by: java.lang.ClassCastException: java.lang.String
       at org.hibernate.type.LongType.set(LongType.java:42)
       at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:83)
       at org.hibernate.type.NullableType.nullSafeSet(NullableType.java:65)
       at org.hibernate.loader.Loader.bindPositionalParameters(Loader.java:1514)
       at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1576)
       at org.hibernate.loader.Loader.doQuery(Loader.java:661)
       at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
       at org.hibernate.loader.Loader.loadEntity(Loader.java:1785)
       at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:47)
       at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:41)
       at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:2730)
       at org.hibernate.event.def.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:365)
       at org.hibernate.event.def.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:346)
       at org.hibernate.event.def.DefaultLoadEventListener.load(DefaultLoadEventListener.java:123)
       at org.hibernate.event.def.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:177)
       at org.hibernate.event.def.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:87)
       at org.hibernate.impl.SessionImpl.fireLoad(SessionImpl.java:862)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:799)
       at org.hibernate.impl.SessionImpl.get(SessionImpl.java:792)
       at org.jboss.seam.framework.HibernateEntityHome.find(HibernateEntityHome.java:64)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2.CGLIB$find$4(<generated>)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2$$FastClassByCGLIB$$7734317c.invoke(<generated>)
       at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
       at org.jboss.seam.intercept.JavaBeanInterceptor.intercept(JavaBeanInterceptor.java:35)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2.find(<generated>)
       at org.jboss.seam.framework.Home.initInstance(Home.java:54)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2.CGLIB$initInstance$15(<generated>)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2$$FastClassByCGLIB$$7734317c.invoke(<generated>)
       at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
       at org.jboss.seam.intercept.JavaBeanInterceptor.intercept(JavaBeanInterceptor.java:35)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2.initInstance(<generated>)
       at org.jboss.seam.framework.Home.getInstance(Home.java:42)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2.CGLIB$getInstance$24(<generated>)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2$$FastClassByCGLIB$$7734317c.invoke(<generated>)
       at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
       at org.jboss.seam.intercept.JavaBeanInterceptor$3.proceed(JavaBeanInterceptor.java:103)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:57)
       at org.jboss.seam.interceptors.ValidationInterceptor.validateTargetComponent(ValidationInterceptor.java:65)
       at sun.reflect.GeneratedMethodAccessor75.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.OutcomeInterceptor.interceptOutcome(OutcomeInterceptor.java:23)
       at sun.reflect.GeneratedMethodAccessor73.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.RollbackInterceptor.rollbackIfNecessary(RollbackInterceptor.java:30)
       at sun.reflect.GeneratedMethodAccessor72.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.BijectionInterceptor.bijectTargetComponent(BijectionInterceptor.java:51)
       at sun.reflect.GeneratedMethodAccessor74.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.ConversationInterceptor.endOrBeginLongRunningConversation(ConversationInterceptor.java:60)
       at sun.reflect.GeneratedMethodAccessor71.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.BusinessProcessInterceptor.manageBusinessProcessContext(BusinessProcessInterceptor.java:50)
       at sun.reflect.GeneratedMethodAccessor70.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.TransactionInterceptor.doInTransactionIfNecessary(TransactionInterceptor.java:35)
       at sun.reflect.GeneratedMethodAccessor69.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.ConversationalInterceptor.checkConversationForConversationalBean(ConversationalInterceptor.java:81)
       at sun.reflect.GeneratedMethodAccessor68.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.EventInterceptor.aroundInvoke(EventInterceptor.java:51)
       at sun.reflect.GeneratedMethodAccessor67.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.RemoveInterceptor.removeIfNecessary(RemoveInterceptor.java:40)
       at sun.reflect.GeneratedMethodAccessor66.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.ExceptionInterceptor.handleExceptions(ExceptionInterceptor.java:45)
       at sun.reflect.GeneratedMethodAccessor65.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.interceptors.AsynchronousInterceptor.invokeAsynchronouslyIfNecessary(AsynchronousInterceptor.java:32)
       at sun.reflect.GeneratedMethodAccessor64.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:17)
       at org.jboss.seam.intercept.Interceptor.aroundInvoke(Interceptor.java:172)
       at org.jboss.seam.intercept.SeamInvocationContext.proceed(SeamInvocationContext.java:66)
       at org.jboss.seam.intercept.RootInterceptor.invokeInContexts(RootInterceptor.java:168)
       at org.jboss.seam.intercept.RootInterceptor.invoke(RootInterceptor.java:141)
       at org.jboss.seam.intercept.RootInterceptor.aroundInvoke(RootInterceptor.java:128)
       at org.jboss.seam.intercept.JavaBeanInterceptor.interceptInvocation(JavaBeanInterceptor.java:96)
       at org.jboss.seam.intercept.JavaBeanInterceptor.intercept(JavaBeanInterceptor.java:58)
       at org.jboss.seam.framework.HibernateEntityHome$$EnhancerByCGLIB$$c7b9cad3_2.getInstance(<generated>)
       ... 137 more
      
      


        • 1. Re: Problem with HibernateEntity when id is not of type Stri
          Carsten Hoehne Master

          Hello,
          totally my fault. now solved.
          With HibernateManagedEntity you could outject only Objects of type String,
          So HibernateManagedEntity has to convert a String to the real object type (e.g.long) .For this purpose ther was the attribute idclass.

          Now,
          with HibernateEntity, you can outject the real object type. No need for conversion (good job,gavin).

          The solution was easy. At every location where bazExperimentId is outjected ireplace

           @Out(required=false)
           private String bazExperimentID;
          

          with the original type of the identifier
           @Out(required=false)
           private Long bazExperimentID;
          


          and all is well.
          Ciao,
          Carsten