昨天在试书里的一个例子,程序运行时提示如下错误:
ERROR [main] ( CGLIBLazyInitializer.java : 130 ) - CGLIB Enhancement failed: hibernate.ch05.section02.SC - [org.hibernate.proxy.CGLIBLazyInitializer] -org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:130)
net.sf.cglib.core.CodeGenerationException: java.lang.reflect.InvocationTargetException-->null
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:237)
at net.sf.cglib.proxy.Enhancer.createHelper(Enhancer.java:377)
at net.sf.cglib.proxy.Enhancer.createClass(Enhancer.java:317)
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:126)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
at org.hibernate.tuple.AbstractEntityTuplizer.<init>(AbstractEntityTuplizer.java:131)
at org.hibernate.tuple.PojoEntityTuplizer.<init>(PojoEntityTuplizer.java:55)
at org.hibernate.tuple.TuplizerLookup.create(TuplizerLookup.java:64)
at org.hibernate.tuple.EntityMetamodel.<init>(EntityMetamodel.java:257)
at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:412)
at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:108)
at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:216)
at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1176)
at hibernate.ch05.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:31)
at hibernate.ch05.HiloTest.save(HiloTest.java:13)
at hibernate.ch05.HiloTest.main(HiloTest.java:47)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at net.sf.cglib.core.ReflectUtils.defineClass(ReflectUtils.java:384)
at net.sf.cglib.core.AbstractClassGenerator.create(AbstractClassGenerator.java:219)
... 17 more
Caused by: java.lang.SecurityException: class "hibernate.ch05.section02.SC$$EnhancerByCGLIB$$daf9d65b"'s signer information does not match signer information of other classes in the same package
at java.lang.ClassLoader.checkCerts(ClassLoader.java:776)
at java.lang.ClassLoader.preDefineClass(ClassLoader.java:488)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
... 23 more
在Google试了很多方法都没有解决,最后修改了hbm.xml里这句:
<class name="hibernate.ch05.section02.SC" table="ch05_sec02_sc" catalog="sxpres">
改成:
<class name="hibernate.ch05.section02.SC" table="ch05_sec02_sc" catalog="sxpres" lazy="false">
具体的原因还不确定,网上有个朋友对这个字段的说明是:
1---lazy="false"时,用Session.load()方法加载一个Customer对象时,就执行了SQL语句,而后面对Customer的调用,都是直接从最开始执行的SQL语句得到的结果中取值,不再执行SQL语句.
2---lazy="true"时,用Session.load()方法加载一个Customer对象时,不执行SQL语句,而后面对Customer的调用时,才会执行相应的SQL语句.