posts - 0,  comments - 0,  trackbacks - 0
           

            1.通過《Ant介紹及使用》部署和測(cè)試Ant,確保能正常使用

            配置環(huán)境變量

            測(cè)試

            2.在項(xiàng)目根目錄下建立一個(gè)build.xml文件,把下面的內(nèi)容Copy進(jìn)去

            <?xml version="1.0" encoding="GBK"?>

            <project name="構(gòu)建腳本" default="生成Hibernate配置文件" basedir=".">

             

            <property name="src.dir" value="${basedir}/src"/>

            <property name="build.dir" value="${basedir}/bin"/>

            <property name="webapp.dir" value="${basedir}/src/webapp"/>

            <property name="xdoclet.home" value="D:/opensources/xdoclet/xdoclet-plugins-1.0.3"/>

             

            <!-- Build classpath -->

            <path id="xdoclet.task.classpath">

            <fileset dir="${xdoclet.home}/lib">

            <include name="**/*.jar"/>

            </fileset>

            <fileset dir="${xdoclet.home}/plugins">

            <include name="**/*.jar"/>

            </fileset>

            </path>

            <taskdef

            name="xdoclet"

            classname="org.xdoclet.ant.XDocletTask"

            classpathref="xdoclet.task.classpath"

            />

            <target name="生成Hibernate配置文件">

            <xdoclet>

            <fileset dir="${src.dir}/com/yzk/oa/model">

            <include name="**/*.java"/>

            </fileset>           

            <component

            classname="org.xdoclet.plugin.hibernate.HibernateConfigPlugin"

            destdir="${src.dir}"

            version="3.0"

            hbm2ddlauto="update"

            jdbcurl="jdbc:mysql://127.0.0.1/oa"

            jdbcdriver="com.mysql.jdbc.Driver"

            jdbcusername="root"

            jdbcpassword="root"

            dialect="org.hibernate.dialect.MySQLDialect"

            showsql="true"

            />

            </xdoclet>

            </target>

            <target name="生成hibernate映射文件">

            <xdoclet>

            <fileset dir="${src.dir}/com/yzk/oa/model">

            <include name="**/*.java"/>

            </fileset>

            <component

            classname="org.xdoclet.plugin.hibernate.HibernateMappingPlugin"

            version="3.0"

            destdir="${src.dir}"

            />

            </xdoclet>

            </target>

            </project>

            3.修改內(nèi)容,主要要修改的部分以黃色標(biāo)注

            上面的數(shù)據(jù)庫是以MySQL為例子,如果是Oracle或者其他則要相應(yīng)的其他數(shù)據(jù)庫變量

            4.對(duì)實(shí)體類進(jìn)行Xdoclet注釋,以便解析

            package com.yzk.oa.model;

             

            import java.util.Set;

            /**

             * @hibernate.class table="t_org1"

             * @author Administrator

             *

             */

            public class Organization {

            /**

             * @hibernate.id generator-class="native"

             */

            private int id;

            /**

             * @hibernate.property

             */

            private String name;

            /**

             * @hibernate.property

             */

            private String sn;

            /**

             * @hibernate.property

             */

            private String description;

            /**

             * @hibernate.many-to-one column="pid"

             */

            private Organization parent;

            /**

             * @hibernate.set lazy="extra" inverse="true"

             * @hibernate.key column="pid"

             * @hibernate.one-to-many class="com.yzk.oa.model.Organization"

             */

            private Set children;

             

            。。。。。這時(shí)省略了get/set內(nèi)容。。。。。

            public void setDescription(String description) {

            this.description = description;

            }

            }

            package com.yzk.oa.model;

            /**

             * @hibernate.class table="t_person1"

             * @author Administrator

             *

             */

            public class Person {

            /**

             * @hibernate.id

             *         generator-class="native"

             */

            private int id;

            /**

             * @hibernate.property

             */

            private String name;

            /**

             * @hibernate.property

             */

            private String sex;

            /**

             * @hibernate.property

             */

            private String address;

            /**

             * @hibernate.property

             */

            private int age;

            /**

             * @hibernate.property

             */

            private String duty; //職務(wù)

            /**

             * @hibernate.property

             */

            private String phone;

            /**

             * @hibernate.many-to-one

             */

            private Organization org;

             

            。。。。省略了Get/Set代碼。。。。。

            }

            5.可以利用ant工具來生成了,這里我使用MyEclipse中內(nèi)置的ant工具來生成

            window-show views-ant/ant 

            Add Buildfiles --選擇項(xiàng)目中的build.xml文件

            右鍵運(yùn)行即可,然后刷新項(xiàng)目就可以看到生成的映射文件及配置文件了

            6.大功告成~~~~

          posted on 2008-12-28 13:11 游上岸的魚 閱讀(375) 評(píng)論(0)  編輯  收藏

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           

          <2025年7月>
          293012345
          6789101112
          13141516171819
          20212223242526
          272829303112
          3456789

          留言簿

          文章檔案

          搜索

          •  

          最新評(píng)論

          主站蜘蛛池模板: 盐源县| 丹寨县| 杨浦区| 仁化县| 广汉市| 临颍县| 雅江县| 西藏| 博野县| 锡林浩特市| 阿拉善左旗| 建瓯市| 都匀市| 遵义市| 中江县| 雷州市| 南乐县| 赣榆县| 吉林省| 宁城县| 平塘县| 嘉善县| 奈曼旗| 花垣县| 河曲县| 津南区| 稻城县| 阳曲县| 紫金县| 红桥区| 常熟市| 荥经县| 唐山市| 黄山市| 佛坪县| 长阳| 卓资县| 绥化市| 辽中县| 横峰县| 淮北市|