Home >Database >Mysql Tutorial >Hibernate-类映射文件中常用属性的了解

Hibernate-类映射文件中常用属性的了解

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-07 17:09:06801browse

Hibernate-类映射文件中常用属性的了解,我们把User.hbm.xml加了一些扩展来说说常用的属性的含义:

我们把User.hbm.xml加了一些扩展来说说常用的属性的含义:

这里没有指定column属性表示与name值相同

length="20" 如果前台提交过来的值长度超过20的话Hibernate会抛出异常

not-null="true" 如果前台提交过来的值是空的Hibernate会抛出异常

unique="true" 如果前台提交过来的值已经在数据中存在Hibernate会抛出异常(Hibernate会自动去判断是否在数据库是有重复数据)

update="false" 表示该字段不参与更新操作(Hibernate不会产生该字段的SQL语句)

insert="true" 表示该字段参与插入操作。

可以修改成如下表示方法

是主键生成策略,是Hibernate自动生成的。

这里讲解下代理主键和业务主键的概念

代理主键是指与业务无关且能唯一标识数据库中记录,一般是数据库自动生成的,比如mysql可以使用auto_increment,Sql2000可以使用identity生成方式,Oracle可以使用sequence生成方式

业务主键指业务相关,由用户指定,且能唯一标识数据库中的任意一条记录,也叫自然主键

Hibernate可以帮助生成业务主键

就是一种生成方式,下面我说详细说下hibernate中业务主键的生成方式:


increment:以递增方式生成OID,每次加1
identiry:由底层数据库生成OID,条件是数据库支持自动增加的字段
sequence: hibernate根据底层数据库的序列来生成OID,条件是数据库支持序列
hilo:根据high/low算法生成OID,Hibernate根据待定表的字段作为high值,,默认采用hibernate_unique_key表的next_hi值
seqhilo:hibernate3.0出现,根据高氏位算法生成主键,需要给顶一个序列。
native:根据数据库的情况自动选择OID生成的方式
uuid.hex:采用128位的uuid算法生成OID,占用空间大
assigned:由JAVA应用程序负责生成主键,适用于自然主键

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:C++ 下MongoDB使用Next article:MongoDB配置脚本