title: Another entities-cannot-be-cast-to-javassist-util-proxy-proxy
body: <p>Following thread [entities cannot be cast to javassist.util.proxy.Proxy, i do have now a server side error ( tks thomas)
  I wasn't able to face the real problem within my app.</p>
  
  <pre><code>java.lang.ClassCastException: org.nit.persistance.entities.Manufacturers_.$$_javassist_3 cannot be cast to javassist.util.proxy.Proxy
      at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:148)
      at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:73)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:758)
      at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4419)
      at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:333)
      at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:259)
      at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
      at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1017)
      at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:944)
      at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:671)
      at org.hibernate.type.EntityType.resolve(EntityType.java:489)
      at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168)
      at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1112)
      at org.hibernate.loader.Loader.processResultSet(Loader.java:969)
      at org.hibernate.loader.Loader.doQuery(Loader.java:917)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:318)
      at org.hibernate.loader.Loader.loadEntity(Loader.java:2143)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
      at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3939)
      at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:461)
      at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:430)
      at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:207)
      at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:263)
      at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
      at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1017)
      at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:173)
      at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2413)
      at org.hibernate.internal.SessionImpl.get(SessionImpl.java:913)
      at org.nit.persistance.dao.impl.FichesImpl.readbyPK(FichesImpl.java:24)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at com.sun.proxy.$Proxy13.readbyPK(Unknown Source)
      at org.nit.server.CEM.CEMFiches.fetch(CEMFiches.java:52)
      at org.nit.server.service.FichesService.fetch(FichesService.java:11)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.google.web.bindery.requestfactory.server.ReflectiveServiceLayer.invoke(ReflectiveServiceLayer.java:182)
      at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.invoke(ServiceLayerDecorator.java:111)
      at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.invoke(ServiceLayerDecorator.java:111)
      at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processInvocationMessages(SimpleRequestProcessor.java:463)
      at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:233)
      at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:135)
      at com.google.web.bindery.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:133)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:324)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)java.lang.ClassCastException: org.nit.persistance.entitesManufacturers_.$$_javassist_3 cannot be cast to javassist.util.proxy.Proxy
      at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:148)
      at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:73)
      at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:758)
      at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4419)
      at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:333)
      at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:259)
      at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
      at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1017)
      at org.hibernate.internal.SessionImpl.internalLoad(SessionImpl.java:944)
      at org.hibernate.type.EntityType.resolveIdentifier(EntityType.java:671)
      at org.hibernate.type.EntityType.resolve(EntityType.java:489)
      at org.hibernate.engine.internal.TwoPhaseLoad.doInitializeEntity(TwoPhaseLoad.java:168)
      at org.hibernate.engine.internal.TwoPhaseLoad.initializeEntity(TwoPhaseLoad.java:137)
      at org.hibernate.loader.Loader.initializeEntitiesAndCollections(Loader.java:1112)
      at org.hibernate.loader.Loader.processResultSet(Loader.java:969)
      at org.hibernate.loader.Loader.doQuery(Loader.java:917)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:348)
      at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:318)
      at org.hibernate.loader.Loader.loadEntity(Loader.java:2143)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:82)
      at org.hibernate.loader.entity.AbstractEntityLoader.load(AbstractEntityLoader.java:72)
      at org.hibernate.persister.entity.AbstractEntityPersister.load(AbstractEntityPersister.java:3939)
      at org.hibernate.event.internal.DefaultLoadEventListener.loadFromDatasource(DefaultLoadEventListener.java:461)
      at org.hibernate.event.internal.DefaultLoadEventListener.doLoad(DefaultLoadEventListener.java:430)
      at org.hibernate.event.internal.DefaultLoadEventListener.load(DefaultLoadEventListener.java:207)
      at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:263)
      at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:151)
      at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1017)
      at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:173)
      at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.load(SessionImpl.java:2413)
      at org.hibernate.internal.SessionImpl.get(SessionImpl.java:913)
      at org.nit.persistance.dao.impl.FichesImpl.readbyPK(FichesImpl.java:24)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150)
      at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:110)
      at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
      at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204)
      at com.sun.proxy.$Proxy13.readbyPK(Unknown Source)
      at org.nit.server.CEM.CEMFiches.fetch(CEMFiches.java:52)
      at org.nit.server.service.FichesService.fetch(FichesService.java:11)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
      at java.lang.reflect.Method.invoke(Unknown Source)
      at com.google.web.bindery.requestfactory.server.ReflectiveServiceLayer.invoke(ReflectiveServiceLayer.java:182)
      at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.invoke(ServiceLayerDecorator.java:111)
      at com.google.web.bindery.requestfactory.server.ServiceLayerDecorator.invoke(ServiceLayerDecorator.java:111)
      at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.processInvocationMessages(SimpleRequestProcessor.java:463)
      at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:233)
      at com.google.web.bindery.requestfactory.server.SimpleRequestProcessor.process(SimpleRequestProcessor.java:135)
      at com.google.web.bindery.requestfactory.server.RequestFactoryServlet.doPost(RequestFactoryServlet.java:133)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
      at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
      at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:362)
      at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
      at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
      at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:729)
      at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.handler.RequestLogHandler.handle(RequestLogHandler.java:49)
      at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
      at org.mortbay.jetty.Server.handle(Server.java:324)
      at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:505)
      at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:843)
      at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:647)
      at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:211)
      at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:380)
      at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:395)
      at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:488)
  </code></pre>
  
  <p>What does this part means ?</p>
  
  <pre><code>at com.sun.proxy.$Proxy13.readbyPK(Unknown Source)
  at org.nit.server.CEM.CEMFiches.fetch(CEMFiches.java:52)
  at org.nit.server.service.FichesService.fetch(FichesService.java:11)
  </code></pre>
  
  <p>Error is on Manufacturers entity, but I am working on Fiches.</p>
  
  <ul>
  <li>Fiches is linked by a many-to-one relation with References </li>
  <li>References is linked by a many-to-one relation with Products </li>
  <li>Products is linked by a many-to-one relation with Manufacturers.</li>
  </ul>
  
  <p>Could it be a problem with one of my proxies ?</p>
  
  <p><strong>CEMFiches :</strong> ( Line 52 is return fichesDAO.readbyPK(fichesPK);)</p>
  
  <pre><code> public static Fiches fetch (String metier, String sitegeo, String cptdossier, Integer numligne) {
          if (fichesDAO == null) {
            HttpServletRequest request = RequestFactoryServlet.getThreadLocalRequest();
            ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(request.getSession().getServletContext());
            fichesDAO =context.getBean(IFichesDAO.class);
  
        }
          try {
                  FichesPK fichesPK = new FichesPK(metier,sitegeo, cptdossier, numligne);
                  return fichesDAO.readbyPK(fichesPK);
              } catch (PersistanceException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
              return null;
        }
  </code></pre>
  
  <p><strong>IfichesDAO</strong> is ( @transactional is used )</p>
  
  <pre><code>public interface IFichesDAO {
      @Transactional(readOnly=true)
      public void save(Fiches fiches) throws PersistanceException;
      public Fiches readbyPK(FichesPK fichesPK) throws PersistanceException;
  
  }
  </code></pre>
  
  <p><strong>FichesImpl</strong> is</p>
  
  <pre><code>@Transactional(readOnly=true)
  public Fiches readbyPK(FichesPK fichesPK){
      return (Fiches)getSessionFactory().getCurrentSession().get(Fiches.class, fichesPK);
  }
  </code></pre>
  
  <p><strong>FichesService</strong> :</p>
  
  <pre><code>public class FichesService
  {
      public Fiches fetch(FichesPK id) { return CEMFiches.fetch(id); }
      public FichesPK fetchPK(FichesPK id) { return CEMFiches.fetchPK(id); }
      public Fiches fetch(String metier, String sitegeo, String cptdossier, Integer numligne) { return CEMFiches.fetch(metier, sitegeo, cptdossier, numligne); }
  
  
  }
  </code></pre>