Hibernate: CGLIB Enhancement failed:

今天刚下载了一个最新版本的MyHibernate,建了一个Spring + Hibernate + Proxool项目,一开始就遇到问题了,出现了以下错误:

错误信息
2006-09-27 22:57:20,217 WARN [org.hibernate.tuple.PojoEntityTuplizer] - <could not create proxy factory for:com.xu.ycoe.impl.UserDaoImpl>
org.hibernate.HibernateException: CGLIB Enhancement failed: com.xu.ycoe.impl.UserDaoImpl
at org.hibernate.proxy.CGLIBLazyInitializer.getProxyFactory(CGLIBLazyInitializer.java:132)
at org.hibernate.proxy.CGLIBProxyFactory.postInstantiate(CGLIBProxyFactory.java:41)
at org.hibernate.tuple.PojoEntityTuplizer.buildProxyFactory(PojoEntityTuplizer.java:161)
......

这种错误在官方里是这么说的: http://www.hibernate.org/116.html#A5

官方说法
If you use lazy loading with proxies (default for all classes in Hibernate 3), Hibernate needs to subclass your class at runtime. It can't do this if you have a private no-argument constructor. As per documentation, at least package visibility is required.

但是,无论怎样检查,都没有这种可能!
在网上,还有一个网友这么说的:
http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=next_topic&f=78&t=001663&go=older

网友:Travis Hein
I recently found I was having this problem too, when I was not before.

It turns out that it was something to do with having more than one version of the cglib jar file in the web app's class path. Though I am not sure if it is this jar file, or any of the other jar files that hibernate uses and depends on, as I also had the rest of the hibernate jar files in the class path in a different version.

By removing conflicting versions of the cglib & other jars, things worked again.

My environment was using tomcat, i had set up my instance to place a bunch of commonly used, third party jar files into ${CATALINA_BASE}/shared/lib folder, since the webapps i was running in this tomcat instance all were using the same version of hibernate, struts, etc.

(Note that the shared/lib folder is the one on your CATALINA_BASE, or instance, not the CATALINA_HOME, the installation folder for tomcat, though most default installed instances, these are the same, just one of those things that drove me nuts at first...)

With these jar files located here, they are loaded according to the servlet spec / tomcat's class loader tree as:
${CATALINA_HOME}/common/lib
${CATALINE_BASE}/shared/lib
<the webapp>/WEB-INF/lib

This particular war file i was building was packaging (an older version) of hibernate.jar and its supporting third party jar files into the war file.
so something was amiss there; removing them from the jar file (as the newer ones i had in the shared/lib folder would provide for my webapp)

I guess one could also have removed them from the shared/lib and made each web app have their own copy of the jar files.

I have found though with tomcat 5, now that it uses commons logging, it likes to have log4j in the common/lib folder.

有两个不同版本的cglib.jar 在应用程序路径内
但我找了好久都没有找到...

这次,由于不同版本让我想到了可能会因为其它三方包是不同版本引起的,因此仔细检查了一下,哈哈
Hibernate!!!
Hibernate的各个版本的兼容性的确不是很好,因为我刚下载的是最新的MyEclipse,所以里面的Hibernate也是最新的3.1(它里面还带有一个3.0版本的)。却和Spring一起工作不是很好,在路径里删除,再换上3.0版本,马上正常工作,原以为是这个原因,但是当我导入Hibernate Advanced Support Liberaries时,又没有那种错误出现。倒是新的Proxool的报错:

错误代码
2000-02-27 22:46:35,171 INFO [org.logicalcobwebs.proxool.DBPool] - Shutting down 'DBPool' pool immediately [Shutdown Hook]
2000-02-27 22:46:35,203 ERROR [org.logicalcobwebs.proxool.ShutdownHook] - Problem calling "get cause" on IllegalStateException.
java.lang.reflect.InvocationTargetException
 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.logicalcobwebs.proxool.ShutdownHook.remove(ShutdownHook.java:40)
 at org.logicalcobwebs.proxool.ProxoolFacade.shutdown(ProxoolFacade.java:238)
 at org.logicalcobwebs.proxool.ProxoolFacade.shutdown(ProxoolFacade.java:220)
 at org.logicalcobwebs.proxool.ShutdownHook.run(ShutdownHook.java:99)
 at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: Shutdown in progress
 at java.lang.Shutdown.remove(Unknown Source)
 at java.lang.Runtime.removeShutdownHook(Unknown Source)
 ... 9 more

      郁闷...高级功能支持,算了,暂时用不着...

你可能感兴趣的:(Hibernate)