Coder Social home page Coder Social logo

qiangzhu / uuid-jpa-rest-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from otrosien/uuid-jpa-rest-example

0.0 2.0 0.0 122 KB

Example of using UUIDs as primary keys in EclipseLink / Spring-Data REST

License: Apache License 2.0

Java 100.00%

uuid-jpa-rest-example's Introduction

JPA UUID primary key example

Build Status

Example project for demonstrating the use of UUIDs as primary keys in JPA and Spring Data REST. Current master branch uses hibernate as implementation, while the eclipselink tag shows an alternative implementation using EclipseLink as JPA provider.

Special Features

UUID as primary key

This service is using UUIDs as primary keys. The UUID is not naïvely persisted into the DB as CHAR(36), but shifted into a BYTE(16) structure.

It is using the Java Uuid Generator library for generating Version-1 UUIDs, still hiding the actual implementation behind a functional interface ( UUIDGenerator ).

Business vs. technical identifiers

In addition to the id, which is immutable, there is the name property as business identifier of a resource. Most business identifiers in the wild are not immutable, unfortunately. Still, by default the URI is composed using the business identifier, creating human-readable URIs. For the case of "renamed mice", there is still the possibility of a look-up via the finder resource /search/findById.

JPA auditing and optimistic locking

The Mouse entity has support for last-modified-based and ETag-based optimistic locking. The extra properties ( optLock, createdAt, lastModifiedAt ) are hidden from the business model and resource representations (i.e. private fields without getters/setters)

EclipseLink load-time weaving

Although not directly related to UUID persistence, this project also applies EclipseLink's load-time weaving, but only when spring-instrument.jar is present on the classpath. (see the eclipselink tag)

How to run

On the command-line run ./gradlew bootRun and open a browser at http://localhost:8080/.

Further references:

uuid-jpa-rest-example's People

Watchers

Qiang avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.