一:主键生成策略大体分类: 1:hibernate 负责对主键ID赋值  2:应用程序自己为主键ID赋值(不推荐使用) 3:底层数据库为主键ID赋值
        二:具体用法
         1:increment:(跨平台的)  以递增的方式为代理主键赋值,每次维护的当前实例中取出一个最大值,在最大值的基础之上再进行加法,适合只有单个应用进程访问数据的情况,否则会产生并发冲突问题(主键重复)。并且oid  的类型必须是long ,int ,short类型的。
          2:assigned :由程序员给赋值,(不建议使用)
   3:identity:是由底层的数据库来生成主键,他要求底层数据库支持自动增长,并且把主键定义成自动增长类型的 ,oid 必须是long ,int  ,short 类型的。 Oracle 不支持。Mysql 支持
  4:sequence:由底层的数据根据序列来生成主键。oracle  ,db2数据库支持,mysql不支持
  5:native:(跨平台的) 由hibernate  自己跟据不同的数据库的主键生成方式,自己选择生成方式(可以跨平台)
   6:hilo  :(跨平台的),通过hi/lo算法实现主键的生成机制,但是需要额外的表来保存主键的生成历史,使用时要先插入一个值。 使用规则: 通用性和安全性: 
  7:seqhilo:取得sequence的值,来生成高位,产生id。 但是只能使用于有sequence的数据库(oracle , db2); 
  8:uuid.hex: 用系统时间和ip地址等具有天然唯一性的资源进行计算,生成id,  全球唯一。生成的是一个128位的二进制数。然后把这个二进制数,转化成一个16进制的数(32位),再转化为字符串付给我们的id。那么我们的实体类的oid以及数据库的主键都需要随之改为字符串类型的。 
  9:foreign 用于共享主键的时候。(一对一主键关联);
 

hibernate ID的更多相关文章

  1. org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.String

    org.hibernate.id.IdentifierGenerationException: Unknown integral data type for ids : java.lang.Strin ...

  2. Hibernate —— ID的各种生成器(转)

    Hibernate中,<id>元素下的可选<generator>子元素是一个Java类的名字,用来为该持久化类的实例生成惟一标示,所有的生成器都实现net.sf.hiberna ...

  3. org.hibernate.id.IdentifierGenerationException

    [问题]org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned bef ...

  4. Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values;

    项目部署,启动过程中有以下警告: [WARN]: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 41 ...

  5. 异常:org.hibernate.id.IdentifierGenerationException

    在有关联关系的数据表中保存数据时,先保存一端,再保存多端的抛出的异常(此时不管一端,还是多端的对象都没有设置id,属性,也就是要保存的两个对象的id 属性为空.) org.hibernate.id.I ...

  6. 【hibernate】主键生成策略使用UUID报出如下警告:org.hibernate.id.UUIDHexGenerator - HHH000409: Using org.hibernate.id.UUIDHexGenerator which does not generate IETF RFC 4122 compliant UUID values;

    主键生成策略使用UUID报出如警告如下: 控制台- 2017-11-24 18:40:14 [restartedMain] WARN org.hibernate.id.UUIDHexGenerator ...

  7. org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()

    org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before ...

  8. org.hibernate.id.IdentifierGenerationException错误解决方法

    org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before ...

  9. Caused by: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save(): com.qingmu.seller.entity.OrderMaster

    org.springframework.orm.jpa.JpaSystemException: ids for this class must be manually assigned before ...

  10. org.hibernate.id.IdentifierGenerationException: Hibernate异常

    异常信息: org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned b ...

随机推荐

  1. Java框架相关

    问题及答案来源自<Java程序员面试笔试宝典>第五章 Java Web 5.3 框架 11.什么是IoC? IoC:控制反转(Inverse of Control, IoC),有时候也被称 ...

  2. Eclipse中JSP生成的class文件去了哪里?

    转自:http://www.cnblogs.com/xing901022/p/4352999.html 首先应该了解的是Tomcat在Eclipse的映射关系,参考前一篇博文所述:Tomcat的服务器 ...

  3. iOS保存gif动态图

    - (void)saveImageToPhotos:(NSData*)gifData { /***注意先倒入库 #import <AssetsLibrary/AssetsLibrary.h> ...

  4. pip 国内源

    pip install django -i http://mirrors.aliyun.com/pypi/simple --trusted-host mirrors.aliyun.com pip in ...

  5. python 插入html到数据库 re.escape() PyMysql

    python 把html 网页源码插入到mysql 成功,部分汉字乱码是 mysql编码问题

  6. Windows下python库的常用安装方法

    目录:       1.pip安装(需要pip)       2.通过下载whl文件安装(需要pip)       3.在pythn官网下载安装包安装(不需要pip)   方法一:pip安装. 这是最 ...

  7. mysql中表里的数据重新设置自增的id的方法

    如果删除表数据用这个 TRUNCATE TABLE tablename 如果不删除表 alter table table_name AUTO_INCREMENT=;

  8. python 函数参数 *a **kw

    f(name='a') name >>> def f(*a,**kw): print a for i in kw: print i >>> f([1,2],n='a ...

  9. 关于 jquery+ajax向asp.net传递json的问题研究(呕心沥血、柳暗花明)

    第一种方法:字典的方法 //质检不合格 $('#Button3').click(function () { if (!confirm('确定质检不合格吗?')) return; var obj = n ...

  10. leetcode1002

    class Solution: def commonChars(self, A: 'List[str]') -> 'List[str]': n = len(A) if n == 1: retur ...