Java Sequence Generator examples

An example to show you how to create a thread safe sequence generator. 1. SequenceGenerator SequenceGenerator.java package com.mkyong.concurrency.examples.sequence.generator; public interface SequenceGenerator { long getNext(); } 1.1 First try, read, add, write the value directly. Below method is not thread safe, multiple threads may get the same value at the same time. UnSafeSequenceGenerator.java package com.mkyong.concurrency.examples.sequence.generator; public …

Read more

JPA Insert + Oracle Sequences example

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 …

Read more

Spring Boot + Spring Data JPA + Oracle example

In this article, we will show you how to create a Spring Boot + Spring Data JPA + Oracle + HikariCP connection pool example. Tools used in this article : Spring Boot 1.5.1.RELEASE Spring Data 1.13.0.RELEASE Hibernate 5 Oracle database 11g express Oracle JDBC driver ojdbc7.jar HikariCP 2.6 Maven Java 8 1. Project Structure A …

Read more