Hibernate Class Generation Using hbm2java

Hibernate Class Generation Using hbm2java

Generating the Classes for a Real-World Project

Actually, hbm2java is designed to convert one hibernate mapping file into a corresponding set of Java classes. If you want to use this approach for a real application, it would be obviously more convenient to generate the classes for all of the Hibernate mapping files in one fell swoop. The best way to do this is integrate the class-generation task into your automated build process.



Integrating into an Ant Build Process

Invoking hbm2java using Ant is fairly straightforward. First, you need to declare the hbm2java task so that Ant can invoke it:


  

     <taskdef name="hbm2java"

                classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"

                classpathref="project.class.path"/>

  

Next, you use this task; for example, by writing a target to generate source code for all of the *.hbm.xml files in the source directory. Suppose ${src.hibernate} represents the directory containing the Hibernate mapping files, and ${src.generated} the directory where you want the source code to go. The Ant task could look something like this:

  

       <target name="codegen"

               description="Generate Java source code

                            from the Hibernate mapping files">

         <hbm2java output="${source.generated}">

           <fileset dir="${src.hibernate}">

             <include name="**/*.hbm.xml"/>

           </fileset>

         </hbm2java>

       </target>

  

Prev  [1] [2] [3] [4] [5] [6] Next

Close    To Top
  • Prev Article-Java:
  • Next Article-Java:
  • Now: Tutorial for Web and Software Design > Java > JDOnJDBCnSQLJ > Java Content
    Photoshop Tutorial
     

    Special Effect

      3D Effect
      Photoshop Articles
    Programming Tutorial
     

    C/C++ Tutorial

      Visual Basic
      C# Tutorial
    Database Tutorial
     

    MySQL Tutorial

      MS SQL Tutorial
      Oracle Tutorial
    Geek Tutorial
     

    Blogging Tutorial

      RSS Tutorial
      Podcasting Tutorial
    Graphic Design Tutorial
      Coreldraw Tutorial
      Illustrator Tutorial
      3D Tutorials
    Webmaster Articles
     

    Domain Service

      Web Hosting
      Site Promotion
    Java Tutorial/ Articles
     

    Java Servlets

      JavaEE Tutorial
     

    JavaBeans Tutorial

    XML Tutorial/ Articles
     

    XML Style

      AJAX Tutorial
      XML Mobile
    Flash Tutorial/ Articles
     

    Flash Video

      Action Script
      Flash Articles
    OS Tutorial/ Articles
      Linux Tutorial
      Symbian Tutorial
      MacOS Tutorial
    Personal Tech
      Hardware Tutorial
      Software Tutorial
      Online Auction