大家好,我用hibernate3和hibernate-extensions-2.1.3工具來根據映射文件生成java類文件,我的setenv.bat配置文件如下:
@echo off
rem -------------------------------------------------------------------
rem Setup environment for hibernate tools
rem -------------------------------------------------------------------
set JDBC_DRIVER=D:/Middlegen-Hibernate-r5/lib/commons-collections-2.1.jar
set HIBERNATE_HOME=D:/hibernate-3.0
set HIBERNATETOOLS_HOME=D:/hibernate-extensions-2.1.3/tools
echo HIBERNATETOOLS_HOME set to %HIBERNATETOOLS_HOME%
if "%HIBERNATE_HOME%" == "" goto noHIBERNATEHome
set CORELIB=%HIBERNATE_HOME%/lib
set LIB=%HIBERNATETOOLS_HOME%/lib
set CP=%CLASSPATH%;%JDBC_DRIVER%;%HIBERNATE_HOME%/hibernate3.jar;%CORELIB%/commons-logging-1.0.4.jar;%CORELIB%/commons-lang-1.0.1.jar;%CORELIB%/commons-collections-2.1.1.jar;%CORELIB%/cglib-2.1.jar;%CORELIB%/dom4j-1.6.jar;%CORELIB%/odmg-3.0.jar;%CORELIB%/xml-apis.jar;%CORELIB%/xerces-2.6.2.jar;%CORELIB%/xalan-2.4.0.jar;%LIB%/jdom.jar;%HIBERNATETOOLS_HOME%/hibernate-tools.jar
if not "%HIBERNATE_HOME%" == "" goto end
:noHIBERNATEHome
echo HIBERNATE_HOME is not set. Please set HIBERNATE_HOME.
goto end
:end
在相應文件路徑下執行:hbm2java d:/hbm/model/*.xml --output=d:/hbm/java/時,出現如下所示的錯誤提示信息:HIBERNATETOOLS_HOME set to D:/hibernate-extensions-2.1.3/tools
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/hibernate/MappingException,我也不知道是怎麼回
用hibernate3出現了以上錯誤,但是用hibernate2.17就沒有問題,
估計是包名的錯誤,原來是net.sf.現在是org.hibernate
*********************************************************************************
我在自己的機器上試了2天,用Middle-gen生成.hbm.xml沒有問題,但是在hbm2java的時候,始終報:
Exception in thread "main" java.lang.NoClassDefFoundError: net/sf/hibernate/tool/hbm2java/CodeGenerator
我知道是上面說的org.hibernate的原因,但是沒有解決。始終沒有找到合適的hibernate-extension的包,hibernatehome設置用的Hibernate開始用的是3.2,後來2.1的final也用了,2.1.3 ,2.1.6都用了,都不行,估計是hibernate-extension的版本不對,繼續嘗試把。