<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    每日一得

    不求多得,只求一得 about java,hibernate,spring,design,database,Ror,ruby,快速開發(fā)
    最近關(guān)心的內(nèi)容:SSH,seam,flex,敏捷,TDD
    本站的官方站點(diǎn)是:顛覆軟件

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      220 隨筆 :: 9 文章 :: 421 評(píng)論 :: 0 Trackbacks
    到網(wǎng)上搜索了半天都說(shuō)什么要在hbm.xml文件里寫什么implements equals,但是心想如果都在這個(gè)里面手工寫那還有什么方便之處啊.

    原因終于找到,原來(lái)是高版本不行,我用的是2.1.2,而2.0.2則沒問(wèn)題,確切的說(shuō)把hibernate-tools.jar換為2.0.2的即可

    附配置說(shuō)明:
    不需要記復(fù)雜的命令,只要一次配置好Middlegen-Hibernate-r5目錄下的build.xml文件即可,以后則需要運(yùn)行
    ant

    ant hbm2java即可
    注:前者生成數(shù)據(jù)庫(kù)對(duì)應(yīng)的所有hbm.xml文件,后者生成hbm.xml對(duì)應(yīng)的所有POJO

    build.xml配置如下:
    <?xml version="1.0"?>

    <!-- 
    This is a testing platform for the middlegen hibernate plugin. It is a stripped
    down version of the samples application. At the moment it is only concerned
    with the generation of the mapping documents so that various tests etc can be
    done on the generated package.

       David Channon


    The DOCTYPE declaration declares the location of product-specific parts of the
    Ant build file. You can change the values of these declarations to point to
    other available files. This gives you an opportunity to choose what database.

    Note that this syntax has nothing to do with Ant or Middlegen. This
    is the standard way defined by w3c to dynamically include external
    files in an XML document. Any decent XML parser will do the include
    transparently. Try to open this file in Internet Explorer and see
    for yourself.
    -->

    <!DOCTYPE project [
        <!ENTITY database SYSTEM "file:./config/database/mysql.xml"
    >
    ]>


    <project name="Middlegen Hibernate" default="all" basedir=".">

    <!-- project name="Middlegen Hibernate" default="all" basedir="." -->
     
       
    <property file="${basedir}/build.properties"/>
       
    <property name="name" value="bona"/>

       
    <property name="myPackage" value="cn.com.chinagc.cpms.model.po"/>

       
    <!-- This was added because we were several people (in a course) deploying to same app server>
       <property environment="env"/>
       <property name="unique.name"                    value="${name}.${env.COMPUTERNAME}"/
    -->

       
    <property name="gui"                            value="false"/>

       
    <property name="unique.name"                    value="${name}"/>

       
    <property name="appxml.src.file"                value="${basedir}/src/application.xml"/>
       
    <property name="lib.dir"                        value="${basedir}/lib"/>
       
    <property name="src.dir"                        value="${basedir}/src"/>
       
    <property name="java.src.dir"                   value="${src.dir}/java"/>
       
    <property name="web.src.dir"                    value="${src.dir}/web"/>
       
       
    <property name="build.dir"                      value="${basedir}/build"/>
       
    <property name="build.java.dir"                 value="${build.dir}/java"/>
       
    <property name="build.gen-src.dir"              value="${build.dir}/gen-src"/>
       
    <property name="build.classes.dir"              value="${build.dir}/classes"/>

       
    &database;
       
       
    <!-- define the datasource.jndi.name in case the imported ejb file doesn't -->
       
    <property name="datasource.jndi.name"           value="${name}/datasource"/>

       
    <path id="lib.class.path">
          
    <pathelement path="${database.driver.classpath}"/>
          
    <fileset dir="${lib.dir}">
             
    <include name="*.jar"/>
          
    </fileset>
          
    <!-- The middlegen jars -->
          
    <!--fileset dir="${basedir}/.."-->
          
    <fileset dir="${basedir}/middlegen-lib">
             
    <include name="*.jar"/>
          
    </fileset>
       
    </path>

       
    <target name="init">
          
    <available property="xdoclet1.2+" classname="xdoclet.modules.hibernate.HibernateDocletTask" classpathref="lib.class.path"/>
       
    </target>

       
    <!-- =================================================================== -->
       
    <!-- Fails if XDoclet 1.2.x is not on classpath                          -->
       
    <!-- =================================================================== -->
       
    <target name="fail-if-no-xdoclet-1.2" unless="xdoclet1.2+">
          
    <fail>
          You must download several jar files before you can build Middlegen.
          
    </fail>
       
    </target>

       
    <!-- =================================================================== -->
       
    <!-- Create tables                                                       -->
       
    <!-- =================================================================== -->
       
    <target 
          
    name="create-tables" 
          depends
    ="init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present" 
          description
    ="Create tables"
       
    >
          
    <echo>Creating tables using URL ${database.url}</echo>
          
    <sql
             
    classpath="${database.driver.classpath}"
             driver
    ="${database.driver}"
             url
    ="${database.url}"
             userid
    ="${database.userid}"
             password
    ="${database.password}"
             src
    ="${database.script.file}"
             print
    ="true"
             output
    ="result.txt"
          
    />
       
    </target>
       
    <target name="check-driver-present">
          
    <available file="${database.driver.file}" type="file" property="driver.present"/>
       
    </target>
       
    <target name="panic-if-driver-not-present" unless="driver.present">
          
    <fail>
          The JDBC driver you have specified by including one of the files in ${basedir}/config/database
          doesn't exist. You have to download this driver separately and put it in ${database.driver.file}
          Please make sure you're using a version that is equal or superior to the one we looked for.
          If you name the driver jar file differently, please update the database.driver.file property
          in the ${basedir}/config/database/xxx.xml file accordingly.
          
    </fail>
       
    </target>

       
    <!-- =================================================================== -->
       
    <!-- Run Middlegen                                                       -->
       
    <!-- =================================================================== -->
       
    <target 
          
    name="middlegen" 
          description
    ="Run Middlegen" 
          unless
    ="middlegen.skip"
          depends
    ="init,fail-if-no-xdoclet-1.2,check-driver-present,panic-if-driver-not-present"
       
    >
          
    <mkdir dir="${build.gen-src.dir}"/>

          
    <echo message="Class path = ${basedir}"/>
          
    <taskdef
             
    name="middlegen"
             classname
    ="middlegen.MiddlegenTask"
             classpathref
    ="lib.class.path"
          
    />

          
    <middlegen
             
    appname="${name}"
             prefsdir
    ="${src.dir}"
             gui
    ="${gui}"
             databaseurl
    ="${database.url}"
             initialContextFactory
    ="${java.naming.factory.initial}"
             providerURL
    ="${java.naming.provider.url}"
             datasourceJNDIName
    ="${datasource.jndi.name}"
             driver
    ="${database.driver}"
             username
    ="${database.userid}"
             password
    ="${database.password}"
             schema
    ="${database.schema}"
             catalog
    ="${database.catalog}"
          
    >

             
    <!--
             We can specify what tables we want Data generated for.
             If none are specified, Data will be generated for all tables.
             Comment out the <table> elements if you want to generate for all tables.
             Also note that table names are CASE SENSITIVE for certain databases,
             so on e.g. Oracle you should specify table names in upper case.
             
    -->
             
    <!--table generate="true" name="flights" pktable="flights_pk"/>
             <table name="reservations"/
    -->

             
    <!--
             If you want m:n relations, they must be specified like this.
             Note that tables declare in multiple locations must all have
             the same value of the generate attribute.
             
    -->
             
    <!--many2many>
                <tablea generate="true" name="persons"/>
                <jointable name="reservations" generate="false"/>
                <tableb generate="true" name="flights"/>
             </many2many
    -->


             
    <!-- Plugins - Only Hibernate Plugin has been included with this special distribution  -->
             
             
    <!--
             If you want to generate XDoclet markup for hbm2java to include in the POJOs then
             set genXDocletTags to true. Also, composite keys are generated as external classes which is
             recommended. If you wish to keep them internal then set genIntergratedCompositeKeys to true.
             Since r4 the ability to customise the selection of JavaTypes is now provided. The is a 
             recommended type mapper provided as shown. It is optional - if not provided then Middlegen
             itself will select the Java mapping (as it did previously).
             These settings are optional thus if they are not define here values default to false.
             
    -->
             
    <hibernate
                
    destination="${build.gen-src.dir}"
                package
    ="${myPackage}"
                genXDocletTags
    ="true"
                genIntergratedCompositeKeys
    ="false"
                javaTypeMapper
    ="middlegen.plugins.hibernate.HibernateJavaTypeMapper"
             
    />
             
          
    </middlegen>

          
    <mkdir dir="${build.classes.dir}"/>
       
    </target>

       
    <!-- =================================================================== -->
       
    <!-- Compile business logic (hibernate)                                        -->
       
    <!-- =================================================================== -->
       
    <target name="compile-hibernate" depends="middlegen" description="Compile hibernate Business Domain Model">
          
    <javac
             
    srcdir="${build.gen-src.dir}"
             destdir
    ="${build.classes.dir}"
             classpathref
    ="lib.class.path"
          
    >
             
    <include name="**/hibernate/**/*"/>
          
    </javac>
       
    </target>
       
       
    <!-- =================================================================== -->
       
    <!-- Run hbm2java    depends="middlegen"                                 -->
       
    <!-- =================================================================== -->
       
    <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>

       
    <!-- =================================================================== -->
       
    <!-- Build everything                                                    -->
       
    <!-- =================================================================== -->
       
    <target name="all" description="Build everything" depends="compile-hibernate"/>

       
    <!-- =================================================================== -->
       
    <!-- Clean everything                                                    -->
       
    <!-- =================================================================== -->
       
    <target name="clean" description="Clean all generated stuff">
          
    <delete dir="${build.dir}"/>
       
    </target>

       
    <!-- =================================================================== -->
       
    <!-- Brings up the hsqldb admin tool                                     -->
       
    <!-- =================================================================== -->
       
    <target name="hsqldb-gui" description="Brings up the hsqldb admin tool">
          
    <property name="database.urlparams" value="?user=${database.userid}&amp;password=${database.password}"/>
          
    <java 
             
    classname="org.hsqldb.util.DatabaseManager" 
             fork
    ="yes" 
             classpath
    ="${lib.dir}/hsqldb-1.7.1.jar;${database.driver.classpath}"
             failonerror
    ="true"
          
    >
             
    <arg value="-url"/>
             
    <arg value="${database.url}${database.urlparams}"/>
             
    <arg value="-driver"/>
             
    <arg value="${database.driver}"/>
          
    </java>
       
    </target>

       
    <!-- ==================================================================== -->
       
    <!-- Validate the generated xml mapping documents                         -->
       
    <!-- ==================================================================== -->
       
    <target name="validate">
          
    <xmlvalidate failonerror="no" lenient="no" warn="yes">
               
    <fileset dir="${build.gen-src.dir}/airline/hibernate" includes="*.xml" />
          
    </xmlvalidate>
       
    </target>
       
    </project>

    記得把2.0.2下面的hibernate-tools.jar文件拷貝到Middlegen-Hibernate-r5\lib下
    ,當(dāng)然config下面的數(shù)據(jù)庫(kù)配置文件也要設(shè)置為你自己的環(huán)境

    如果你不想用ant來(lái)自動(dòng)化做也可以通過(guò)dos命令行的方式來(lái)執(zhí)行,命令如下:
    hbm2java c:\sample\org\hibernate\sample\*.xml --output=c:\sample\
    ,前提是要設(shè)置下hibernate-extensions-2.1.2\tools\bin下的setenv.dat文件
    posted on 2006-02-17 22:56 Alex 閱讀(1242) 評(píng)論(0)  編輯  收藏 所屬分類: java
    主站蜘蛛池模板: 亚洲美国产亚洲AV| 免费观看黄色的网站| 亚洲另类自拍丝袜第五页| 免费永久在线观看黄网站| 东方aⅴ免费观看久久av| 看亚洲a级一级毛片| 国产精品亚洲精品日韩已满| 日本特黄a级高清免费大片| 国产成人精品免费视频大全麻豆 | 亚洲va在线va天堂va四虎| 国产一级理论免费版| 成年女性特黄午夜视频免费看| 一区二区三区免费看| 亚洲人成影院77777| 青青草原精品国产亚洲av| 亚洲乱码精品久久久久..| 亚洲国产精品综合久久网络| 国产乱弄免费视频| 国产妇乱子伦视频免费| 91在线老王精品免费播放| 日本不卡免费新一区二区三区| 亚洲精品乱码久久久久久蜜桃图片| 亚洲国产精品无码久久久不卡| 国产极品美女高潮抽搐免费网站| 久久伊人免费视频| 无码人妻精品中文字幕免费| 免费无码作爱视频| 国产拍拍拍无码视频免费| 相泽南亚洲一区二区在线播放| 亚洲日韩乱码中文无码蜜桃臀| 久久精品亚洲男人的天堂| 久久亚洲色一区二区三区| 亚洲综合精品网站| 奇米影视亚洲春色| 国产成人亚洲精品狼色在线| 日本免费v片一二三区| 99久久国产热无码精品免费| 100000免费啪啪18免进| 免费精品国产自产拍在| 免费国产黄线在线观看| 免费的涩涩视频在线播放|