hibernate + oracle 实现id的自增

1.在oracle中先创建一个序列 : 序列语法 如下

create  sequence   (序列名称)seq_student_id
minvalue 1
start with 1
increment by 1
cache 20;

创建序列 seq_student_id

2.在实体类中添加相应的注释

@SequenceGenerator(name="zoedemo",sequenceName="seq_student_id")   name="zoedemo"是数据库名称  sequenceName="seq_student_id”是序列名称

@GeneratedValue(strategy=GenerationType.SEQUENCE,generator="zoedemo")  generator是数据库名称

@SequenceGenerator(name="zoedemo",sequenceName="seq_student_id",allocationSize=1)  后面最后一个提示的是按照1自增 不然会随机自增

操作后 即可得出这样结果

3.如果是用Hibernate的配置文件用下面这种方

结果一样

方法2:使用hibrenate自带的自增注释

@GeneratedValue(strategy=GenerationType.AUTO)

也是可以实现的自增操作

select seq_student_id.nextval from dual 将会变为 select hibernaet  nextval from dual

hibernate项目跑起来 会自己增加字段的原因

在hibernate添加注释的 时候要全部

添加进去

不然会hibnate自己会创建列 使得与原先的oracle自己创建的列重复  name="user_name"

2017/2/8 hibernate + oracle 实现id的自增 同时 hibernate项目跑起来 会自己增加字段的原因 oracle触发器的使用的更多相关文章

  1. hibernate解决oracle的id自增?

    以前做SSH项目时,涉及到的数据库是mySQL,只需将bean的配置文件id设为native 就可以实现表id的自增. 现在用到了Oracle,当然知道这样是不行的啦,那么用序列自增? 我在网络上搜索 ...

  2. Hibernate在oracle中ID增长的方式

    引用链接:http://blog.csdn.net/w183705952/article/details/7367272 Hibernate在oracle中ID增长的方式 第一种:设置ID的增长策略是 ...

  3. hibernate generator class="" id详解

    “assigned”   主键由外部程序负责生成,在   save()   之前指定一个.         “hilo”   通过hi/lo   算法实现的主键生成机制,需要额外的数据库表或字段提供高 ...

  4. Hibernate 再接触 ID生成策略

    Xml 方法 在student.hbm.xml中 <generator class="uuid"></generator> 取值如下 1.identity: ...

  5. 报错:org.hibernate.AssertionFailure: null id in com.tt.hibernate.entities.News entry (don't flush the Session after an exception occurs)

    在使用hibernate创建数据库的表格时,出现了如下报错: 十二月 28, 2016 10:17:02 上午 org.hibernate.tool.hbm2ddl.SchemaExport perf ...

  6. org.hibernate.AssertionFailure: null id in xxx.xx.xx的问题

    今日在开发时遇到一个比较奇怪的问题,保存时报这个异常: org.hibernate.AssertionFailure: null id in com.aa.TShoucang null id,这个是什 ...

  7. org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User. Expected: class java.lang.String, got class java.lang.Integer at org.hibernate.event.internal.Defau

    出现org.hibernate.TypeMismatchException: Provided id of the wrong type for class cn.itcast.entity.User ...

  8. 【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 ...

  9. org.hibernate.AssertionFailure: null id in com.you.model.User entry (don&#39;t flush the Session after a

    1.错误描写叙述 org.hibernate.AssertionFailure: null id in com.you.model.User entry (don't flush the Sessio ...

随机推荐

  1. JPA in

    CriteriaBuilder.In in = criteriaBuilder.in(root.get("field1")); for (String str : arr) { i ...

  2. php判断文件夹是不是存在

    function MkFolder($path){   if(!is_readable($path)){     MkFolder( dirname($path) );     if(!is_file ...

  3. 六:python 对象类型详解二:字符串(下)

    一:字符串方法: 方法就是与特定对象相关联在一起的函数.从技术的角度来讲,它们是附属于对象的属性,而这些属性不过是些可调用的函数罢了.Python 首先读取对象方法,然后调用它,传递参数.如果一个方法 ...

  4. awk技巧 nginx access.log

    1.1 介绍 awk其名称得自于它的创始人 Alfred Aho .Peter Weinberger 和 Brian Kernighan 姓氏的首个字母.实际上 AWK 的确拥有自己的语言: AWK ...

  5. pta7-18奥运排行榜(模拟)

    题目链接:https://pintia.cn/problem-sets/1101307589335527424/problems/1101314114867245056 题意:给n个国家,以及每个国家 ...

  6. Ubuntu 14.04 LTS 安装Docker(转)

    转自:https://www.cnblogs.com/leolztang/p/5097278.html Docker官方是有很详细的安装文档(https://docs.docker.com/engin ...

  7. 51nod 1163 最高的奖励

    链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1163 1163 最高的奖励  基准时间限制:1 秒 空间限制:13 ...

  8. 倒计时问题java

    public static void main(String args[]){ Scanner sc = new Scanner(); int x = sc.nextInt(); System.out ...

  9. JETTY+NGINX

    一.Jetty搭建 1)上传jetty.tar,并且解压(支持war和文件夹) [root@localhost home]# tar -xvf jetty.tar [root@localhost ho ...

  10. Spring Cloud入门教程(二):客户端负载均衡(Ribbon)

    对于大型应用系统负载均衡(LB:Load Balancing)是首要被解决一个问题.在微服务之前LB方案主要是集中式负载均衡方案,在服务消费者和服务提供者之间又一个独立的LB,LB通常是专门的硬件,如 ...