Hibernate的映射文件(hbm.xml)属性说明
2011-08-24 17:18
405 查看
Hibernate的映射文件(hbm.xml)属性说明
1.class 元素
name: 类名
table: 类对应表名,默认为类名称
dynamic-update: 生成更新字段时,只包含发生变动的字段,默认为false。
dynamic-insert: 生成insert语句时仅包含非null字段
Proxy: 代理类,默认为空
discriminator-value: 子类辨别标识用于多态支持
where: 通过限定条件查询结果集。如:查询有籍在校学生的信息可以使用"where studentstatus='0'"
------------------------------------------------------------------------------------------------------------------
2.id 元素
1.column 字段名称
2.type 字段类型
3.length 字段长度
4.unsaved-value 用于判断对象值是否已经保存
5.name 类里面的属性名
6.generator class 主键产生方式
assigned
hilo
seqhilo
increment
identity
sequence
native
uuid.hex
uuid.string
foreign
---------------------------------------------------------------------------------------------------------------
主键产生方式说明
increment(递增)
用于为long, short或者int类型生成唯一标识。只有在没有其他进程往同一张表中插入数据时才能使用。 在集群下不要使用。
identity
对DB2,MySQL, MS SQL Server, Sybase和HypersonicSQL的内置标识字段提供支持。返回的标识符是long, short 或者int类型的。
sequence (序列)
在DB2,PostgreSQL, Oracle, SAP DB, McKoi中使用序列(sequence),而在Interbase中使用生成器(generator)。返回的标识符是long, short或者 int类型的。
hilo (高低位)
使用一个高/低位算法来高效的生成long, short或者 int类型的标识符。给定一个表和字段(默认分别是是hibernate_unique_key 和next_hi)作为高位值得来源。高/低位算法生成的标识符只在一个特定的数据库中是唯一的。在使用JTA获得的连接或者用户自行提供的连接中,不要使用这种生成器。
seqhilo(使用序列的高低位)
使用一个高/低位算法来高效的生成long, short或者 int类型的标识符,给定一个数据库序列(sequence)的名字。
uuid.hex
用一个128-bit的UUID算法生成字符串类型的标识符。在一个网络中唯一(使用了IP地址)。UUID被编码为一个32位16进制数字的字符串。
uuid.string
使用同样的UUID算法。UUID被编码为一个16个字符长的任意ASCII字符组成的字符串。不能使用在PostgreSQL数据库中
native(本地)
根据底层数据库的能力选择identity, sequence 或者hilo中的一个。
assigned(程序设置)
让应用程序在save()之前为对象分配一个标示符。
说明主键是自己定的,不是数据库生成的,用户注册的帐号一般就属于这种类型。
foreign(外部引用)
-------------------------------------------------------------------------------------------------------------------------
3.property
元素
1.column 数据库表字段名称
2.type 类型
3.length 长度
4.not-null 字段是否允许为空
5.unique 字段是否允许唯一(是否允许重复值)
6.insert insert操作时,是否允许包含本字段数值
7.update update操作时,是否包含本字段数据
====================================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.oreilly.hh.Track" table="TRACK">
<meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliot(with help from Hibernate)
</meta>
<id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<property name="title" type="string" not-null="true"/>
<property name="filePath" type="string" not-null="true"/>
<property name="playTime" type="time">
<meta attribute="field-description">Playing time</meta>
</property>
<property name="added" type="date">
<meta attribute="field-description">When the track was created</meta>
</property>
<property name="volume" type="short" not-null="true">
<meta attribute="field-description">How loud to play the track</meta>
</property>
</class>
</hibernate-mapping>
说明如下:
1.<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
用于导言说明,说明它的文件格式定义。
2.<hibernate-mapping>标签里是真正的映射。
3.<class name="com.oreilly.hh.Track" table="TRACK">
定义一个类com.oreilly.hh.Track的映射。(可以定义任意多个类在一个映射文件里)。表示存在数据库表TRACK中。
4. <meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliot(with help from Hibernate)
</meta>
定义了说明,可以被JavaDoc读取。
5. <id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
定义了类属性和数据库表列的映射。 <generator class="native"/>是表示ID生成策略,此种策略有多种。(请查看“主键产生方式说明”部分)
6. <property name="volume" type="short" not-null="true">
<meta attribute="field-description">How loud to play the track</meta>
</property>
定义了说明,可以被JavaDoc读取。
1.class 元素
name: 类名
table: 类对应表名,默认为类名称
dynamic-update: 生成更新字段时,只包含发生变动的字段,默认为false。
dynamic-insert: 生成insert语句时仅包含非null字段
Proxy: 代理类,默认为空
discriminator-value: 子类辨别标识用于多态支持
where: 通过限定条件查询结果集。如:查询有籍在校学生的信息可以使用"where studentstatus='0'"
------------------------------------------------------------------------------------------------------------------
2.id 元素
1.column 字段名称
2.type 字段类型
3.length 字段长度
4.unsaved-value 用于判断对象值是否已经保存
5.name 类里面的属性名
6.generator class 主键产生方式
assigned
hilo
seqhilo
increment
identity
sequence
native
uuid.hex
uuid.string
foreign
---------------------------------------------------------------------------------------------------------------
主键产生方式说明
increment(递增)
用于为long, short或者int类型生成唯一标识。只有在没有其他进程往同一张表中插入数据时才能使用。 在集群下不要使用。
identity
对DB2,MySQL, MS SQL Server, Sybase和HypersonicSQL的内置标识字段提供支持。返回的标识符是long, short 或者int类型的。
sequence (序列)
在DB2,PostgreSQL, Oracle, SAP DB, McKoi中使用序列(sequence),而在Interbase中使用生成器(generator)。返回的标识符是long, short或者 int类型的。
hilo (高低位)
使用一个高/低位算法来高效的生成long, short或者 int类型的标识符。给定一个表和字段(默认分别是是hibernate_unique_key 和next_hi)作为高位值得来源。高/低位算法生成的标识符只在一个特定的数据库中是唯一的。在使用JTA获得的连接或者用户自行提供的连接中,不要使用这种生成器。
seqhilo(使用序列的高低位)
使用一个高/低位算法来高效的生成long, short或者 int类型的标识符,给定一个数据库序列(sequence)的名字。
uuid.hex
用一个128-bit的UUID算法生成字符串类型的标识符。在一个网络中唯一(使用了IP地址)。UUID被编码为一个32位16进制数字的字符串。
uuid.string
使用同样的UUID算法。UUID被编码为一个16个字符长的任意ASCII字符组成的字符串。不能使用在PostgreSQL数据库中
native(本地)
根据底层数据库的能力选择identity, sequence 或者hilo中的一个。
assigned(程序设置)
让应用程序在save()之前为对象分配一个标示符。
说明主键是自己定的,不是数据库生成的,用户注册的帐号一般就属于这种类型。
foreign(外部引用)
-------------------------------------------------------------------------------------------------------------------------
3.property
元素
1.column 数据库表字段名称
2.type 类型
3.length 长度
4.not-null 字段是否允许为空
5.unique 字段是否允许唯一(是否允许重复值)
6.insert insert操作时,是否允许包含本字段数值
7.update update操作时,是否包含本字段数据
====================================================================
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.oreilly.hh.Track" table="TRACK">
<meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliot(with help from Hibernate)
</meta>
<id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
<property name="title" type="string" not-null="true"/>
<property name="filePath" type="string" not-null="true"/>
<property name="playTime" type="time">
<meta attribute="field-description">Playing time</meta>
</property>
<property name="added" type="date">
<meta attribute="field-description">When the track was created</meta>
</property>
<property name="volume" type="short" not-null="true">
<meta attribute="field-description">How loud to play the track</meta>
</property>
</class>
</hibernate-mapping>
说明如下:
1.<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
用于导言说明,说明它的文件格式定义。
2.<hibernate-mapping>标签里是真正的映射。
3.<class name="com.oreilly.hh.Track" table="TRACK">
定义一个类com.oreilly.hh.Track的映射。(可以定义任意多个类在一个映射文件里)。表示存在数据库表TRACK中。
4. <meta attribute="class-description">
Represents a single playable track in the music database.
@author Jim Elliot(with help from Hibernate)
</meta>
定义了说明,可以被JavaDoc读取。
5. <id name="id" type="int" column="TRACK_ID">
<meta attribute="scope-set">protected</meta>
<generator class="native"/>
</id>
定义了类属性和数据库表列的映射。 <generator class="native"/>是表示ID生成策略,此种策略有多种。(请查看“主键产生方式说明”部分)
6. <property name="volume" type="short" not-null="true">
<meta attribute="field-description">How loud to play the track</meta>
</property>
定义了说明,可以被JavaDoc读取。
相关文章推荐
- Hibernate的映射文件(hbm.xml)属性说明
- Hibernate的映射文件(hbm.xml)属性说明
- Hibernate框架中hibernate.properties属性文件,hibernate.cfg.xml配置文件,以及Users.hbm.xml映射文件的配置
- Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明
- Hibernate的映射配置文件*.hbm.xml文件中class和property元素的各属性意义和设置
- Hibernate3.5.4---java application的xml和annotation环境搭建(hibernate.cfg.xml配置文件说明,映射文件Student.hbm.xml说明)
- [原创]java WEB学习笔记77:Hibernate学习之路---Hibernate 版本 helloword 与 解析,.环境搭建,hibernate.cfg.xml文件及参数说明,持久化类,对象-关系映射文件.hbm.xml,Hibernate API (Configuration 类,SessionFactory 接口,Session 接口,Transaction(事务))
- Hibernate实体类映射文件demo.hbm.xml 中的<generator class="?"></generator>的不同属性含义
- Hibernate的hbm.xml文件中相关属性说明
- Hibernate映射文件元素属性说明
- Hibernate数据检索策略和.hbm.xml映射文件
- LocalSessionFactoryBean加载Hibernate 映射文件(hbm.xml)的三种方式及区别
- Hibernate映射文件元素属性说明
- 表的映射文件问题,javaweb+hibernate , .hbm.xml
- struts2与hibernate 复合主外键在映射文件*.hbm.xml中的配置,为双外键的配置方法
- Hibernate-helloworld-2 hbm.xml配置及其属性说明
- 使用oracle数据库和MySQL数据库时hibernate的映射文件.hbm.xml的不同
- hibernate映射文件XXX.hbm.xml配置映射元素详解--对象标识符(OID)
- Hibernate学习--映射文件xxx.hbm.xml详解
- *.hbm.xml映射文件的元素及属性