服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

通过hibernate_tool生成代码和映射文件

它支持eclispe插件方式和ant方式。这里主要将采用ant方式。这样可以脱离eclipse :)

1 准备好hiberbate.cfg.xml .主要是告诉工具取哪的数据库和表格

 

< ?xml version="1.0" encoding="utf-8"?>
< !doctype hibernate-configuration public
        "-//hibernate/hibernate configuration dtd 3.0//en"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
< hibernate-configuration >
    < session-factory>
        < property name="hibernate.connection.driver_class">oracle.jdbc.driver.oracledriver< /property>
        < property name="hibernate.connection.password">tt< /property>
        < property name="hibernate.connection.url">jdbc:oracle:thin:@10.1.248.23:1521:tt< /property>
        < property name="hibernate.connection.username">tt< /property>
        < property name="hibernate.default_schema">tt< /property>
        < property name="hibernate.dialect">org.hibernate.dialect.oracle9dialect< /property>       
        
    < /session-factory>
    
< /hibernate-configuration>

 


2 编写ant脚本。这一步是要定义ant任务,以及生成pojo和hbm.xml配置文件

 


< taskdef name="hibernatetool" 
         classname="org.hibernate.tool.ant.hibernatetooltask" 
         classpathref="project.class.path" />         
         
< target name="hibernatecode">
    < hibernatetool destdir="e:\gg\yy\3123\src">

         < jdbcconfiguration configurationfile="e:\gg\yy\3123\build\hibernate.cfg.xml" packagename="com.tt.wss.hibernate"
        /> 
         < hbm2java>
         < hbm2dao> 
    < /hibernatetool>
< /target> 

 < target name="hibernatehbm">
         < hibernatetool destdir="e:\gg\yy\3123\src">
 
             < jdbcconfiguration configurationfile="e:\gg\yy\3123\build\hibernate.cfg.xml"  packagename="com.asia.wss.hibernate" 
            /> 
             < hbm2hbmxml>
        < /hibernatetool>
< /target>