JPA Insert + Oracle Sequences example

摘要: A quick JPA + Oracle sequences example, for self reference.

A quick JPA + Oracle sequences example, for self reference.

1. Oracle Database

Issue the following SQL script to create a table and a sequence.

CREATE TABLE CUSTOMER(
	ID NUMBER(10) NOT NULL,
	NAME VARCHAR2(100) NOT NULL,
	EMAIL VARCHAR2(100) NOT NULL,
	CREATED_DATE DATE NOT NULL,
	CONSTRAINT CUSTOMER_PK PRIMARY KEY (ID)
);
CREATE SEQUENCE customer_seq
  MINVALUE 1
  MAXVALUE 9999999999
  START WITH 4
  INCREMENT BY 1;

2. JPA

In Java, add JPA annotations like this :

Customer.java
package com.mkyong.model;
import javax.persistence.*;
import java.util.Date;
@Entity
public class Customer {
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "CUST_SEQ")
    @SequenceGenerator(sequenceName = "customer_seq", allocationSize = 1, name = "CUST_SEQ")
    Long id;
    String name;
    String email;
    @Column(name = "CREATED_DATE")
    Date date;
    //...

References

  1. Oracle / PLSQL: Sequences (Autonumber)
  2. Spring Boot + Spring Data JPA + Oracle example

上一篇: Spring Boot + Spring Data MongoDB example
下一篇: Oracle PL/SQL – Rename Trigger
 评论 ( What Do You Think )
名称
邮箱
网址
评论
验证
   
 

 


  • 微信公众号

  • 我的微信

站点声明:

1、一号门博客CMS,由Python, MySQL, Nginx, Wsgi 强力驱动

2、部分文章来源于互联网, 若有侵权, 联系邮箱:summer@yihaomen.com, 同时欢迎大家注册用户,主动发布文章.

3、鄂ICP备14001754号-3, 鄂公网安备 42280202422812号