從映射文件生成資料表
public class HbmToTablesTest {
public static void main(String[] args) {
Configuration config = new Configuration().configure();
System.out.println("Create tables ......");
SchemaExport shemaExprot = new SchemaExport(config);
shemaExprot.create(true, true);
}
}
從資料表生成映射文件與POJO
<?xml version="1.0" encoding="GBK"?>
<project name="利用工具开发Hibernate" default="help" basedir=".">
<!-- ****** 环境设置,可以根据自己的实际配置自行更改 ***** -->
<!-- 源文件目录, 可以通过 项目->属性->Java构建路径 更改 -->
<property name="src.dir" value="./src" />
<!-- 输出的class文件目录,可以通过 项目->属性->Java构建路径 更改 -->
<property name="class.dir" value="./bin" />
<!-- 库文件目录 -->
<property name="lib.dir" value="D:/java/Hibernate/lib" />
<!-- 定义类路径 -->
<path id="project.class.path">
<fileset dir="${lib.dir}">
<include name="*.jar"/>
</fileset>
<pathelement location="${class.dir}" />
</path>
<!-- ************************************************************** -->
<!-- 使用说明 -->
<!-- ************************************************************** -->
<target name="help">
<echo message="利用工具开发Hibernate" />
<echo message="-----------------------------------" />
<echo message="" />
<echo message="提供以下任务:" />
<echo message="" />
<echo message="generate-code --> 运行Hbm2Java,利用 hbm.xml 文件生成Java类文件" />
<echo message="generate-hbm --> 运行HibernateDoclet,生成 Hibernate 类的映射文件" />
<echo message="schemaexport --> 运行SchemaExport,利用 hbm.xml 文件生成数据表" />
<echo message="" />
</target>
<!-- ************************************************************** -->
<!-- Hbm2Java 任务 -->
<!-- ************************************************************** -->
<target name="generate-code" >
<echo message="运行 Hbm2Java 任务, 利用 hbm.xml 文件生成Java类文件"/>
<taskdef name="hbm2java"
classname="net.sf.hibernate.tool.hbm2java.Hbm2JavaTask"
classpathref="project.class.path">
</taskdef>
<hbm2java output="${src.dir}">
<fileset dir="${src.dir}">
<include name="**/*.hbm.xml"/>
</fileset>
</hbm2java>
</target>
<!-- ************************************************************** -->
<!-- HibernateDoclet 任务 -->
<!-- ************************************************************** -->
<target name="generate-hbm" >
<echo message="运行HibernateDoclet,生成 Hibernate 类的映射文件"/>
<taskdef name="hibernatedoclet"
classname="xdoclet.modules.hibernate.HibernateDocletTask"
classpathref="project.class.path">
</taskdef>
<hibernatedoclet destdir="${src.dir}"
excludedtags="@version,@author,@todo" force="true" encoding="GBK"
verbose="true">
<fileset dir="${src.dir}">
<include name="**/*.java"/>
</fileset>
<hibernate version="2.0" xmlencoding="GBK" />
</hibernatedoclet>
</target>
<!-- ************************************************************** -->
<!-- SchemaExport 任务 -->
<!-- ************************************************************** -->
<target name="schemaexport">
<echo message="运行SchemaExport,利用 hbm.xml 文件生成数据表"/>
<taskdef name="schemaexport"
classname="net.sf.hibernate.tool.hbm2ddl.SchemaExportTask"
classpathref="project.class.path">
</taskdef>
<schemaexport config="${src.dir}/hibernate.cfg.xml" quiet="no"
text="no" drop="no" output="schema-export.sql">
</schemaexport>
</target>
</project>
分享到:
相关推荐
HibernateTool的UserGuide!英文版PDF。
使用工具根据数据库反向生成实体类,,同时还可以跟可以自己的需要,按条件生成,生成后的类名字段是也可以根据需要更改。
Hibernate tool的源代码。 可以学习Eclipse Plugin,Code Generator等知识。
通过Hibernate Tool 来实现通过数据库表自动生成Java类和HBM文件
hibernate-tool 插件实现映射文件生成
用以解决 eclipse luna 显示已安装hibernate tools 但视图中不存在 解压按解压包的名字把子项目拷贝到相应的 eclipse安装目录对应的目录中 重启即可
http://blog.csdn.net/wang102010/article/details/9018769
NULL 博文链接:https://jiangyongyuan.iteye.com/blog/1672577
hibernate需要jar包,
myeclipse配置hibernate时出错
hibernate-tools
无法带图发表,请下载附件的word文档,里边有详细的截图! 博文链接:https://hanyou.iteye.com/blog/134799
hibernate-tool.jar 这个jar文件用来和ANT搭配由hbm.xml自动生成数据库schema,和java类
Hibernate3 学习笔记.ppt 一、O/R Mapping 二、Hibernate入门 三、Hibernate映射申明(Mapping declaration) 四、Hibernate Annotations 五、持久化对象的状态和生命周期 六、Hibernate查询 ...八、Hibernate Tool
下载之后先运行ant hibernatetool命令 2. 如果构建成功,那么运行ant compress命令 3. 把在lib目录下生成的PersistenceDemo.jar拷贝到jboss-4.2.1.GA\server\default\lib\目录下 4. 启动JBoss 5. 运行ant 如果...
We will start by describing full-text search technology and why this tool is invaluable in your development toolbox. Then you will learn how to start with Hibernate Search, how to prepare and index ...
在eclipse上通过hibernate工具,将数据库表生成Java类和xml配置文件 总共有2个版本,根据自己的需求使用版本3或者5: 1. hibernate-tools-3.4.0.CR2.jar是修改完成的jar包,直接替换原来的jar包, 重启eclipse即可...
Hibernate工具 jboss Hibernate工具插件安装
NULL 博文链接:https://linjia880714.iteye.com/blog/859334
免费的Hibernate工具,用起来还可以,支持最新的eclipse