Apply middlegen to generate at the same time Java and hbm. XML file

At the beginning of studying hibernate, I tried to use middlegen to generate according to the database structure for the first time Java and hbm. XML file, checked some articles on the Internet, and started the middlegen main interface smoothly, After pressing the [generate] button, it is found that only some. Hbm.xml files are generated (many of these processes are introduced on the Internet, so I won't mention it). I didn't generate. Java files at the same time. I continued to check on the Internet, but what I found was that they were generated using hbm2java. However, I clearly saw that there was a target in the build.xml file of middlegen, and the name was hbm2java. It should be possible to use middlegen to generate. Java files together. Domestic websites searched with baidu.com, I didn't find the answer to tell me how to apply middlegen generation Java file. So I had to go to www.hibernate.com Org. Fortunately, I did find it. Posted here, I hope it will be helpful to those who see it. The main thing is to build < target name = "hbm2java"...... in XML file Replace this paragraph with a simple modification. Replace with the following:

<target name="hbm2java"
    description="Generate .java from .hbm files." depends="init">
    <property name="hbm.dir" location="${build.gen-src.dir}/com/yourcompany/youproject/pojos/"/>
      
    <replaceregexp
  match='cascade="none"'   
  replace='cascade="all"'
  byline="true">
  <fileset dir="${hbm.dir}" includes="MapRequest.hbm.xml,MapRun.hbm.xml" /> 
    </replaceregexp>
    
    <mkdir dir="${build.gen-src.dir}"/>
    <taskdef
    name="hbm2java"
    classname="net.sf.hibernate.tool.hbm2java.hbm2javaTask"
    classpathref="lib.class.path"
    />
    
    <hbm2java output="${build.gen-src.dir}" classpathref="lib.class.path">
    <fileset dir="${build.gen-src.dir}">
    <include name="**/*.hbm.xml"/>
    </fileset>
    </hbm2java>
 </target>

Then you need to get some jar packages into the Lib of middlegen. Including: hibernate2 jar commons-lang-1.0. 1.jar jdom. jar hibernate-tools. jar

These packages can be found in the middlegen extension and hibernate, and then execute the build with ant XML file, command line: ant - file build xml hbm2java

The effect here is still very good.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>