在配置Middlegen Hibernate3过程中遇到的一些问题
1. Couldn't connect to database: encoding not supported!!
解决办法:删除之前的数据库jar包,引入附件中的数据库包db2java.jar、db2jcc_javax.jar、db2jcc.jar
2. 成功生成xml后再生成java文件时异常doesn't support the "output" attribute 与net/sf/hibernate/MappingException
因为引用的是Hibernate3要与之前的Hibernate2配置有很大不同修改配置
Hibernate3:
- <target name="hbm2java" description="Generate .java from .hbm files.">
- <taskdef
- name="hbm2java"
- classname="org.hibernate.tool.ant.HibernateToolTask"
- classpathref="lib.class.path"
- />
- <hbm2java destdir="${build.gen-src.dir}">
- <configuration>
- <fileset dir="${build.gen-src.dir}">
- <include name="**/*.hbm.xml"/>
- </fileset>
- </configuration>
- <hbm2java jdk5="true" />
- lt;/hbm2java>
- </target>
Hibernate2:
- <target name="hbm2java" description="Generate .java from .hbm files.">
- <taskdef
- name="hbm2java"
- classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
- classpathref="lib.class.path"
- />
- <hbm2java output="${build.gen-src.dir}">
- <fileset dir="${build.gen-src.dir}">
- <include name="**/*.hbm.xml"/>
- </fileset>
- </hbm2java>
- </target>
3.Don't use old DTDs, read the Hibernate 3.x Migration Guide!
解决办法:修改middlegen-hibernate-plugin-2.1.jar 中的\middlegen\plugins\hibernate\hibernate.vm
改之前:
- <?xml version="1.0"?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
改之后:
- <?xml version="1.0"?>
- <!DOCTYPE hibernate-mapping PUBLIC
- "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
- "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
完整工程见附件,自己修改build.xml java类及XML文件的输出目录;
- <property name="ehr.basedir" value="<span style="color: #ff9900;">D:\WORK_EHR\workspaceEHR\EHR</span>"/>
[middlegen] No <table> elements specified. Reading all tables. This might take a while...
如果想要生成指定表,可以在middlegen任务节点中添加<table name="tableName"/>
- Middlegen_Hibernate3.rar (6.3 MB)
- 下载次数: 185