OpenJPA + Oracle Identity Column

configuring OpenJPA + Oracle identity column

What is OpenJPA?

Apache OpenJPA is a Java persistence project at The Apache Software Foundation that can be used as a stand-alone POJO persistence layer or integrated into any Java EE compliant container and many other lightweight frameworks, such as Tomcat and Spring.
[Reference]

What is Oracle identity column?

Oracle 12c introduced a new way that allows you to define an identity column for a table, which is similar to the AUTO_INCREMENT column in MySQL or IDENTITY column in SQL Server.

The identity column is very useful for the surrogate primary key column. When you insert a new row into the identity column, Oracle auto-generates and insert a sequential value into the column.
[Reference]

Mapping primary fields of entities done with @Id annotation:

@Id 
private long id;

But OpenJPA will do this mapping with it’s default configuration. To customize identity mapping there is @GeneratedValue annotation.

To use Oracle Identity column:

@Id 
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;

Typically, OpenJPA auto-configures its JDBC behavior and SQL dialect for your database, based on the values of your connection-related configuration properties. There is some built-in dictionaries and for Oracle database there is:

org.apache.openjpa.jdbc.sql.OracleDictionary

There is some parameters in this dictionary, to use identity column feature it is important to set Supportsgetgeneratedkeys to true:

supportsgetgeneratedkeys=true

--

--

--

Java Developer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

I am a software engineer looking to find a remote job with a company in the USA.

I am a software engineer looking to find a remote job with a company in the USA. What is some advice for me?

Shorthand Control Expressions in Ruby

Security Release: Emissary-ingress & Edge Stack 1.14.1, 2.0.2 Developer Preview

READ/DOWNLOAD#^ Advanced C++ Programming Styles an

Recording Screen Video on Android with RecordableSurfaceView

Sprout Coma — a new horizon on the same course

Step-by-step Guide to Choosing the Right Software Testing Partner

Step-by-step Guide to Choosing the Right Software Testing Partner

Save time using Lombok + MapStruct

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Amir Shokri

Amir Shokri

Java Developer

More from Medium

Windows Interactive Services Using Java (JNA)

Apache Thrift and Spring Boot

Hazelcast: Initiation

Liquibase — Exploring with Spring boot and Maven