另一个实体不能强制转换为 javassist-util-proxy-proxy

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21454931/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 08:47:50  来源:igfitidea点击:

Another entities-cannot-be-cast-to-javassist-util-proxy-proxy

javagwtproxyrequestfactorymany-to-one

提问by Tanc

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.

跟随线程 [entities cannot be cast to javassist.util.proxy.Proxy,我现在有一个服务器端错误 (tks thomas) 我无法在我的应用程序中面对真正的问题。

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.access00(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.access00(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)

What does this part means ?

这部分是什么意思?

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)

Error is on Manufacturers entity, but I am working on Fiches.

错误出在制造商实体上,但我正在研究 Fiches。

  • Fiches is linked by a many-to-one relation with References
  • References is linked by a many-to-one relation with Products
  • Products is linked by a many-to-one relation with Manufacturers.
  • Fiches 通过与 References 的多对一关系链接
  • 引用通过与产品的多对一关系链接
  • 产品通过与制造商的多对一关系链接。

Could it be a problem with one of my proxies ?

我的一个代理可能有问题吗?

CEMFiches :( Line 52 is return fichesDAO.readbyPK(fichesPK);)

CEMFiches :(第 52 行是 return fichesDAO.readbyPK(fichesPK);)

 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;
      }

IfichesDAOis ( @transactional is used )

IfichesDAO是(使用@transactional)

public interface IFichesDAO {
    @Transactional(readOnly=true)
    public void save(Fiches fiches) throws PersistanceException;
    public Fiches readbyPK(FichesPK fichesPK) throws PersistanceException;

}

FichesImplis

FichesImpl

@Transactional(readOnly=true)
public Fiches readbyPK(FichesPK fichesPK){
    return (Fiches)getSessionFactory().getCurrentSession().get(Fiches.class, fichesPK);
}

FichesService:

服务

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); }


}

回答by cuilei103

I encountered the same error and the strange thing is that all the other entities in my project run ok, except one. According to Boris the Spider's suggestion, I checked my project and found that there is a jar called weld-osgi-bundle.jar(in theJava EE 6Libraries, provided by myEclipse10.0)contains some javassist code which may be conflict with javassist-3.18.1-GA.jarin my web libraries. So I removed it, and the problem gets solved.

我遇到了同样的错误,奇怪的是我项目中的所有其他实体都运行正常,除了一个。根据Boris the Spider's suggestion,我检查了我的项目,发现有一个名为weld-osgi-bundle.jar的jar(在Java EE 6Libraries中,由myEclipse10.0)包含一些javassist代码可能与javassist-3.18.1-GA.jar冲突in my web libraries. So I removed it, and the problem gets solved.

回答by sjohnr

I also hit this issue while attempting to render an entity as JSON using Spring's @ResponseBody annotation. The issue turned out to be a relationship annotated as @ManyToOne with a FetchType of LAZY. The error message was not at all helpful. Switching to EAGER fetch solved the problem.

我在尝试使用 Spring 的 @ResponseBody 注释将实体呈现为 JSON 时也遇到了这个问题。事实证明,该问题是一个注释为 @ManyToOne 且 FetchType 为 LAZY 的关系。错误消息根本没有帮助。切换到 EAGER fetch 解决了这个问题。

It may be helpful to note that in my case, the target entity also had a relationship of @ManyToOne which was recursive (target table had a foreign key to itself) which was also mapped as LAZY. Both relationships had to be switched to EAGER to get the problem resolved.

注意到在我的情况下,目标实体也有一个@ManyToOne 的关系,它是递归的(目标表有一个指向它自己的外键),它也被映射为 LAZY,这可能会有所帮助。两种关系都必须切换到 EAGER 才能解决问题。

回答by Phyxx

So I ran into this issue, and I thought I would add some additional details for those who might have the same problem.

所以我遇到了这个问题,我想我会为那些可能有同样问题的人添加一些额外的细节。

I had a collection of dependencies, and one imported org.javassist:javassist:3.18.1-GA, while the other imported javassist:javassist:3.11.0.GA.

我有一组依赖项,一个是导入的org.javassist:javassist:3.18.1-GA,另一个是导入的javassist:javassist:3.11.0.GA.

Because of the different groups (it would seem that javassist:javassistbecame org.javassist:javassist), the build tool wasn't excluding one in favour of the other, and my WAR file had both.

由于不同的组(似乎javassist:javassist变成了org.javassist:javassist),构建工具并没有排除一个而支持另一个,而我的 WAR 文件同时拥有这两个。

I had to manually exclude the old javassist dependency, and once it was removed everything was fine.

我不得不手动排除旧的 javassist 依赖项,一旦它被删除,一切都很好。