- 浏览: 115310 次
- 性别:
- 来自: 广州
文章分类
- 全部博客 (63)
- struts (7)
- spring (12)
- Hibernate (14)
- struts+spring+hibernate (11)
- Ajax (1)
- DWR (0)
- JSON (0)
- Junit (0)
- Lucene (15)
- Compass (0)
- Tomcat(Jsp) (0)
- MySql (0)
- JavaScript (0)
- Html (0)
- UML (0)
- Log4j (0)
- Ant (0)
- Acegi (0)
- (My)eclipse (0)
- java2 (0)
- Jakarta Commons (0)
- java Web (0)
- Ruby (0)
- Ruby On Rails (0)
- IBatis (0)
- 版本控制 (0)
- eXtremeComponents (0)
- SiteMesh (0)
- IT相关 (0)
- 电子商务 (0)
- 随笔 (0)
- 正则表达式 (0)
- 测试资料 (0)
- 个人收藏 (0)
- 开发经验 (0)
- 名词解释(java,j2ee) (1)
- 英语 (0)
- java规则引擎 (0)
- CMS系统 (0)
- XML操作 (0)
- jvm (0)
- 开源工具收集 (0)
- webService (2)
最新评论
-
锦毛鼠:
请问下您现在有没有这个demo啊?可以发我看看吗?
cxf webservice身份验证 -
z276356445t:
LZ,你写的类文件怎么和配置文件中的不一样呢,求解.
spring 定时器 -
j2eeli:
感谢共享!
spring 定时器 -
gimy:
写的很清楚,谢谢!
Spring-MultiActionController -
valgrind:
Exception in thread "main& ...
Lucene中文分词组件 JE-Analysis 1.4.0
通过XDoclet可以我们的精力放在编写java源文件上。
具体来说就是:
只有Java: java--->XDoclet(hibernatedoclet)--->Hbm---->SchemaExport(schemaexport,hbm2ddl)---->数据表
1:java源文件编写
420){this.resized=true;this.style.width=420;}" align=top> * Created on 2006-4-7
420){this.resized=true;this.style.width=420;}" align=top> */
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> package com.entity;
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top>420){this.resized=true;this.style.width=420;}" align=top> /** */ /**
420){this.resized=true;this.style.width=420;}" align=top> * @author jkallen
420){this.resized=true;this.style.width=420;}" align=top> * @hibernate.class lazy="true" table="syn_dept"
420){this.resized=true;this.style.width=420;}" align=top> * @hibernate.cache usage="read-write"
420){this.resized=true;this.style.width=420;}" align=top> */
420){this.resized=true;this.style.width=420;}" align=top> 420){this.resized=true;this.style.width=420;}" align=top> public class SynDepartment 420){this.resized=true;this.style.width=420;}"> {
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top>420){this.resized=true;this.style.width=420;}" align=top> /** */ /** 主键 id */
420){this.resized=true;this.style.width=420;}" align=top> private Long id;
420){this.resized=true;this.style.width=420;}" align=top>420){this.resized=true;this.style.width=420;}" align=top> /** */ /** 部门名称 */
420){this.resized=true;this.style.width=420;}" align=top> private String code_name;
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top>420){this.resized=true;this.style.width=420;}" align=top> /** */ /**
420){this.resized=true;this.style.width=420;}" align=top> * @return Returns the id.
420){this.resized=true;this.style.width=420;}" align=top> * @hibernate.id generator-class="native" column="id"
420){this.resized=true;this.style.width=420;}" align=top> */
420){this.resized=true;this.style.width=420;}" align=top> 420){this.resized=true;this.style.width=420;}" align=top> public Long getId() 420){this.resized=true;this.style.width=420;}"> {
420){this.resized=true;this.style.width=420;}" align=top> return id;
420){this.resized=true;this.style.width=420;}" align=top> }
420){this.resized=true;this.style.width=420;}" align=top> 420){this.resized=true;this.style.width=420;}" align=top> public void setId(Long id) 420){this.resized=true;this.style.width=420;}"> {
420){this.resized=true;this.style.width=420;}" align=top> this .id = id;
420){this.resized=true;this.style.width=420;}" align=top> }
420){this.resized=true;this.style.width=420;}" align=top> 420){this.resized=true;this.style.width=420;}" align=top> /** */ /**
420){this.resized=true;this.style.width=420;}" align=top> * @return Returns the code_name.
420){this.resized=true;this.style.width=420;}" align=top> * @hibernate.property column = "code_name"
420){this.resized=true;this.style.width=420;}" align=top> */
420){this.resized=true;this.style.width=420;}" align=top> 420){this.resized=true;this.style.width=420;}" align=top> public String getCode_name() 420){this.resized=true;this.style.width=420;}"> {
420){this.resized=true;this.style.width=420;}" align=top> return code_name;
420){this.resized=true;this.style.width=420;}" align=top> }
420){this.resized=true;this.style.width=420;}" align=top> 420){this.resized=true;this.style.width=420;}" align=top> public void setCode_name(String code_name) 420){this.resized=true;this.style.width=420;}"> {
420){this.resized=true;this.style.width=420;}" align=top> this .code_name = code_name;
420){this.resized=true;this.style.width=420;}" align=top> }
420){this.resized=true;this.style.width=420;}" align=top>}
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top>
这里用到了几种@hibernate标记的用法
@hibernate.class标记指定类的映射代码,lazy="true" table="syn_dept"则如
hibernate的映射文件class元素的属性值具有相同的意义
@hibernate.id标记指定类的OID映射代码
@hibernate.property标记指定类的属性映射代码
另外还可能用到@hibernate.set(如一对多的情况下)
2:XDoclet--->Hbm(写在build.xml文件中,ANT运行)
420){this.resized=true;this.style.width=420;}" align=top> depends ="compileEntity"
420){this.resized=true;this.style.width=420;}" align=top> description ="Generate hibernate mapping documents" >
420){this.resized=true;this.style.width=420;}" align=top> < hibernatedoclet destdir ="${generated.dir}" >
420){this.resized=true;this.style.width=420;}" align=top> < fileset dir ="${src.dir}" >
420){this.resized=true;this.style.width=420;}" align=top> < include name ="**/entity/*.java" />
420){this.resized=true;this.style.width=420;}" align=top> </ fileset >
420){this.resized=true;this.style.width=420;}" align=top> < hibernate version ="2.0" />
420){this.resized=true;this.style.width=420;}" align=top> </ hibernatedoclet >
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> < copy todir ="${classes.dir}" >
420){this.resized=true;this.style.width=420;}" align=top> < fileset dir ="${generated.dir}" />
420){this.resized=true;this.style.width=420;}" align=top> </ copy >
420){this.resized=true;this.style.width=420;}" align=top> </ target >
通过hibernatedoclet就可以生成SynDepartment.hbm.xml映射文件
fileset顾名思义就是过滤文件了。
注:compileEntity--编译java源文件(自定义)
3:SchemaExport---->数据表
420){this.resized=true;this.style.width=420;}" align=top> < schemaexport properties ="${classes.dir}/hibernate.properties"
420){this.resized=true;this.style.width=420;}" align=top> quiet ="no" text ="no" drop ="no"
420){this.resized=true;this.style.width=420;}" align=top> delimiter ="
go
" output ="${sql.dir}/${synup.sql.file}"
420){this.resized=true;this.style.width=420;}" align=top> >
420){this.resized=true;this.style.width=420;}" align=top> < fileset refid ="hibernate.synup.mapping.files" />
420){this.resized=true;this.style.width=420;}" align=top> </ schemaexport >
420){this.resized=true;this.style.width=420;}" align=top> < echo message ="Output sql to file: ${sql.dir}/${sql.file}" />
420){this.resized=true;this.style.width=420;}" align=top> </ target >
420){this.resized=true;this.style.width=420;}" align=top> < fileset id ="hibernate.synup.mapping.files" dir ="${classes.dir}" >
420){this.resized=true;this.style.width=420;}" align=top> < include name ="**/entity/*.hbm.xml" />
420){this.resized=true;this.style.width=420;}" align=top> </ fileset >
quiet:如果为yes,表示不把子DDL脚本输出到控制台
drop:如果为yes,只执行删除数据库中的操作,但不创建新的表
text:如果为yes,只会生成DDL脚本文件,但不会在数据库中执行DDL脚本
output:指定存放DDL脚本文件的目录
config:设定基于XML格式的配置文件, hbm2ddl(schemaexport)工具从这个文件中读取数据库的配置信息
properties:设定基于java属性文件格式的配置文件,hbm2ddl(schemaexport)工具从这个文件中读取DB的配置信息
format:设定DDL脚本中SQL语句的格式
delimiter:为DDL脚本设置行结束符
在ANT中执行:
<target name="initOnlySynup" depends="toHbm,toddl">
</target>
OK,最后生成的映射文件如下:
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> <! DOCTYPE hibernate-mapping PUBLIC
420){this.resized=true;this.style.width=420;}" align=top> "-//Hibernate/Hibernate Mapping DTD 2.0//EN"
420){this.resized=true;this.style.width=420;}" align=top> "http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> < hibernate-mapping >
420){this.resized=true;this.style.width=420;}" align=top> < class
420){this.resized=true;this.style.width=420;}" align=top> name ="com.SynDepartment"
420){this.resized=true;this.style.width=420;}" align=top> table ="syn_dept"
420){this.resized=true;this.style.width=420;}" align=top> dynamic-update ="false"
420){this.resized=true;this.style.width=420;}" align=top> dynamic-insert ="false"
420){this.resized=true;this.style.width=420;}" align=top> >
420){this.resized=true;this.style.width=420;}" align=top> < cache usage ="read-write" />
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> < id
420){this.resized=true;this.style.width=420;}" align=top> name ="id"
420){this.resized=true;this.style.width=420;}" align=top> column ="id"
420){this.resized=true;this.style.width=420;}" align=top> type ="java.lang.Long"
420){this.resized=true;this.style.width=420;}" align=top> >
420){this.resized=true;this.style.width=420;}" align=top> < generator class ="native" >
420){this.resized=true;this.style.width=420;}" align=top> </ generator >
420){this.resized=true;this.style.width=420;}" align=top> </ id >
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> < property
420){this.resized=true;this.style.width=420;}" align=top> name ="code_name"
420){this.resized=true;this.style.width=420;}" align=top> type ="java.lang.String"
420){this.resized=true;this.style.width=420;}" align=top> update ="true"
420){this.resized=true;this.style.width=420;}" align=top> insert ="true"
420){this.resized=true;this.style.width=420;}" align=top> access ="property"
420){this.resized=true;this.style.width=420;}" align=top> column ="code_name"
420){this.resized=true;this.style.width=420;}" align=top> />
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> <!--
420){this.resized=true;this.style.width=420;}" align=top> To add non XDoclet property mappings, create a file named
420){this.resized=true;this.style.width=420;}" align=top> hibernate-properties-SynDepartment.xml
420){this.resized=true;this.style.width=420;}" align=top> containing the additional properties and place it in your merge dir.
420){this.resized=true;this.style.width=420;}" align=top> -->
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> </ class >
420){this.resized=true;this.style.width=420;}" align=top>
420){this.resized=true;this.style.width=420;}" align=top> </ hibernate-mapping >
420){this.resized=true;this.style.width=420;}" align=top>
控制台中部分信息如下:
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] go
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] drop sequence hibernate_sequence
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] go
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] create table syn_dept (
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] id number(19,0) not null,
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] code_name varchar2(255),
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] primary key (id)
420){this.resized=true;this.style.width=420;}" align=top>[schemaexport] )
DB中已经生成syn_dept表了,快去看下吧!
关于Xdoclet 中的hibernate标签更多信息可以参考:
http://xdoclet.sourceforge.net/xdoclet/tags/hibernate-tags.html#@hibernate_collection-key__0__1_
我还在一个网友的博客上看到了他对此的汉化:
http://blog.csdn.net/fasttalk/archive/2005/09/19/484615.aspx
参考资料:Hibernate持久化技术详解
来源:http://www.blogjava.net/Jkallen/archive/2006/04/10/40305.html
发表评论
-
详解Hibernate配置文件中映射元素
2007-09-27 16:09 1335配置文件中映射元素详解 对象关系的映射是用一个XML ... -
Java开源项目Hibernate包作用详
2007-09-27 16:08 876Hibernate一共包括了23个jar包,令人眼花缭乱。本 ... -
Hibernate学习心得--软件设计阶段的模型
2007-09-27 16:07 1021来源:BlogJava∣原文地 ... -
HIbernate参数说明
2007-09-27 16:06 8480 推荐 set节点有以下 ... -
Hibernate 3.0批量更新与删除
2007-09-27 16:06 1535Hibernate 3.0中,Session接口中被废弃的方法 ... -
关于条件查询detachedCriteria的一点体会
2007-09-27 16:03 1253假设要通过stuName查询一个学生Student记录,可以 ... -
使用模板模式简化DAO操作Hibernate
2007-09-27 15:58 979原文出处:http://www.javaresearch.or ... -
为何OpenSessionInView不能同时保存和删除
2007-09-27 15:56 1996... -
Hibernate分页
2007-09-27 15:21 1113连续看了两篇robbin有关DetachedCriteria ... -
应用Hibernate3的DetachedCriteria实现分页查询
2007-09-27 15:19 955Hibernate3提供了DetachedCriteria, ... -
利用Hibernate配置文件生成数据库
2007-09-27 15:07 1759前很多人使用Hibernate作为持久层,如果我们已经写了配置 ... -
Hibernate 3新增XML关系持久性介绍
2007-09-27 14:59 884Hibernate的易用性、高性能和对象关系持久性等高级特性给 ... -
配置Hibernate连接池
2007-09-27 14:54 2592Hibernate自带的连接池性能不高,而且还存在BUG,因此 ...
相关推荐
<property name="xdoclet.home" value="D:/jarpackage/xdoclet-plugins-1.0.3"/> 指出这个文件存放的位置.然后就可以使用了...里面有一个成功的例子 请读者参考 在构建域对象的时候一定要指明在配置文件中的配置信息...
关于用hibernate映射类时涉及到一个问题: 1.先创建数据表再写JOPO类和映射文件 2.先写POJO类,然后映射文件,最后数据库 3.先映射文件,再同时生成POJO类和数据库 第1种 方法有背面向对象原理,而且控制起来不大...
使用最新的ssh搭建起来的框架!希望对初学者有所帮助 hibernate映射文件,配置文件使用的是ant、xdoclet生成的!
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
映射文件生成器(Mapping File Generation) 15.3.1. 运行此工具 16. 示例:父子关系(Parent Child Relationships) 16.1. 关于collections 16.2. 双向的一对多关系(Bidirectional one-to-many) 16.3...
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 1.3.4. 值...
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
2.2.2. 映射文件 2.2.3. Hibernate配置 2.2.4. 用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二部分 - 关联映射 2.3.1. 映射Person类 2.3.2. 一个单向的Set-based关联 2.3.3. 使关联工作 ...
22.2. Hibernate 映射 22.3. Hibernate 代码 23. 示例:复杂映射实例 23.1. Employer(雇主)/Employee(雇员) 23.2. Author(作家)/Work(作品) 23.3. Customer(客户)/Order(订单)/Product(产品) 23.4. 杂例 23.4.1. ...
映射文件生成器(Mapping File Generation) 15.3.1. 运行此工具 16. 示例:父子关系(Parent Child Relationships) 16.1. 关于collections 16.2. 双向的一对多关系(Bidirectional one-to-many) 16.3...
2.2.2. 映射文件 2.2.3. Hibernate配置 2.2.4. 用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二部分 - 关联映射 2.3.1. 映射Person类 2.3.2. 一个单向的Set-based关联 2.3.3. 使关联...
映射文件 2.2.3. Hibernate配置 2.2.4. 用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二部分 - 关联映射 2.3.1. 映射Person类 2.3.2. 一个单向的Set-based关联 2.3.3. 使关联工作 2.3.4...
1.2.2. 映射文件 1.2.3. Hibernate配置 1.2.4. 用Ant构建 1.2.5. 启动和辅助类 1.2.6. 加载并存储对象 1.3. 第二部分 - 关联映射 1.3.1. 映射Person类 1.3.2. 单向Set-based的关联 1.3.3. 使关联工作 ...
2.2.2. 映射文件 2.2.3. Hibernate配置 2.2.4. 用Ant编译 2.2.5. 安装和帮助 2.2.6. 加载并存储对象 2.3. 第二部分 - 关联映射 2.3.1. 映射Person类 2.3.2. 一个单向的Set-based关联 2.3.3. 使关联工作 ...
22.2. Hibernate 映射 22.3. Hibernate 代码 23. 示例:复杂映射实例 23.1. Employer(雇主)/Employee(雇员) 23.2. Author(作家)/Work(作品) 23.3. Customer(客户)/Order(订单)/Product(产品) 23.4. 杂例 23.4.1. ...