javassist_1 cannot be cast to javassist.util.proxy.Proxy
来源:互联网 发布:lol网络不卡瞬移 编辑:程序博客网 时间:2024/05/16 20:29
今天在学hibernate时,看着官方文档,然后建立了一个小程序,代码都是官方文档上直接copy的,在将两张表关联起来时,遇到了问题。
下面贴出错误:
Exception in thread "main" java.lang.ClassCastException: org.hibernate.tutorial.domain.Person_$$_javassist_1 cannot be cast to javassist.util.proxy.Proxy
at org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.getProxy(JavassistLazyInitializer.java:147)
at org.hibernate.proxy.pojo.javassist.JavassistProxyFactory.getProxy(JavassistProxyFactory.java:75)
at org.hibernate.tuple.entity.AbstractEntityTuplizer.createProxy(AbstractEntityTuplizer.java:771)
at org.hibernate.persister.entity.AbstractEntityPersister.createProxy(AbstractEntityPersister.java:4613)
at org.hibernate.event.internal.DefaultLoadEventListener.createProxyIfNecessary(DefaultLoadEventListener.java:349)
at org.hibernate.event.internal.DefaultLoadEventListener.proxyOrLoad(DefaultLoadEventListener.java:270)
at org.hibernate.event.internal.DefaultLoadEventListener.onLoad(DefaultLoadEventListener.java:150)
at org.hibernate.internal.SessionImpl.fireLoad(SessionImpl.java:1070)
at org.hibernate.internal.SessionImpl.access$2000(SessionImpl.java:176)
at org.hibernate.internal.SessionImpl$IdentifierLoadAccessImpl.getReference(SessionImpl.java:2528)
at org.hibernate.internal.SessionImpl.load(SessionImpl.java:945)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:601)
at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:356)
at $Proxy0.load(Unknown Source)
at org.hibernate.tutorial.EventManager.addPersonToEvent(EventManager.java:73)
at org.hibernate.tutorial.EventManager.main(EventManager.java:30)
上网搜了一下,竟然是版本问题,我看的是4.3.4.Final,用的也是4.3.4.Final,按理说应该可以匹配。我下了一个hibernate-core-4.2.7.Final.jar,将原来的jar包换掉,这时候代码中会出现错误提醒。原因是4.3.4.final中用的是build方法:
Configuration cfg = new Configuration();
cfg.configure();
ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).build();
SessionFactory sf = cfg.buildSessionFactory(sr);
而4.2.7中用的是
Configuration cfg = new Configuration();
cfg.configure();
ServiceRegistry sr = new ServiceRegistryBuilder().applySettings(cfg.getProperties()).buildServiceRegistry();
SessionFactory sf = cfg.buildSessionFactory(sr);
改一下就行了。
然后运行程序竟然可以了,我实在无语,这可能是hibernate官方文档的疏忽吧。
- javassist_1 cannot be cast to javassist.util.proxy.Proxy
- $$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
- $$_javassist_1 cannot be cast to javassist.util.proxy.Proxy
- $$_javassist_1 cannot be cast to javassist.util.proxy.Proxy
- User_$$_javassist_1 cannot be cast to javassist.util.proxy.Proxy
- javassist_0 cannot be cast to javassist.util.proxy.Proxy
- javassist_0 cannot be cast to javassist.util.proxy.Proxy
- XXX_$$_javassist_5 cannot be cast to javassist.util.proxy.ProxyObject
- 整合ssh 报错 $$_javassist_13 cannot be cast to javassist.util.proxy.Proxy
- java.lang.ClassCastException: $$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
- SSH整合遇到的问题:model $$_javassist_13 cannot be cast to javassist.util.proxy.Proxy
- 在SSH整合过程中ClassCastException:xxx_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
- 异常处理:User_$$_javassist_1 cannot be cast to javassist.util.proxy.Proxy
- 整合SSH java.lang.ClassCastException: xxx_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
- com.domain.*_$$_javassist_6 cannot be cast to javassist.util.proxy.Proxy问题
- Java.lang.ClassCastException: $$_javassist_2 cannot be cast to javassist.util.proxy.Proxy
- SSH整合完美解决$$_javassist_4 cannot be cast to javassist.util.proxy.Proxy
- cn.itcast.domain.Customer_$$_javassist_0 cannot be cast to javassist.util.proxy.Proxy
- 细数百度公司的知名开源项目
- ModifyStyle()
- IE7,IE8,IE9 字体不能垂直居中, line-height 不起作用的解决方法
- 看板游戏的心得总结
- C++ Jsoncpp源代码编译与解析Json
- javassist_1 cannot be cast to javassist.util.proxy.Proxy
- 银汇通携手手机支付让“成交”无处不在
- android dialog圆角显示及解决出现的黑色棱角
- sql server数据库中With as 的使用解析
- linux找不到动态链接库 .so文件的解决方法
- Valid Palindrome
- CC9
- css3animation动画
- 传智播客2013/2014年ios就业班全套教程/黑马程序员ios就业班全套教程