question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support for java.util.UUID as @Id Column in SQL Databases

See original GitHub issue
Overview of the issue

Feature Request: Allow the use of java.util.UUID as ID with SQL Databases

Motivation for or Use Case

It may not be as fast as Long, but can be generated safely outside the database, being an interesting option for microservices using separate databases

With Spring Data included in Spring Boot 1.5.1, both Spring Data JPA and Spring Data Elasticsearch support Repositories with java.util.UUID as ID. Also Hibernate v5.2.4 (used in JHipster 4) supports @GeneratedValue without the need to define any custom generator

I tested a monolith application using JHipster v4.0.0 with PostgreSQL, using H2 as test database, and after upgrading to Spring Boot 1.5.1, no @UserType or any configuration of the sort was needed, setting the column type as “uuid” in liquibase was enough

I don’t know if the other databases supported by JHipster also support uuid as a column type, but if the user wants to use UUID even if the selected database doesn’t support it, the key could be a varchar(36) or varchar(32) (UUID without dashes)

Related issues

If such feature is added, it’s better to wait until #5045 is merged

JHipster Version(s)

v4

JHipster configuration
Entity configuration(s) entityName.json files generated in the .jhipster directory
Browsers and Operating System
  • Checking this box is mandatory (this is just to show you read everything)

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:9 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
amitjindalcommented, Mar 9, 2017

@DanielSBFranco : I added my code. Its not extensively tested but we have been using this internally for almost 10 months with minimal problems. See here: https://github.com/amitjindal/generator-jhipster-postgresuuid-converter

In next few days I will polish this and submit this to NPM repository.

0reactions
amitjindalcommented, Sep 5, 2017

@DanielSBFranco Just released latest version with change as you requested. Please take a look.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How To Use UUIDs With Hibernate And MySQL
Hibernate supports java.util.UUID and UUID generation. Consequently, Hibernate itself generates the UUID on the client-side.
Read more >
Using the UUID data type - Oracle Help Center
A table column can be declared as having UUID type in a CREATE TABLE statement. The UUID data type is best-suited in situations...
Read more >
Hibernate UUID with PostgreSQL and SQL Server
I would like to use java.util.UUID as the IDs. I have defined my columns in SQL Server as id UNIQUEIDENTIFIER ROWGUIDCOL NOT NULL...
Read more >
How to use String UUID in Hibernate with MySQL | Codementor
Using a unique ID for columns in a table is important. Besides the auto-increment option, we can use the Java UUID column, however, ......
Read more >
How to generate UUIDs as primary keys with Hibernate
Since JPA 3.1, you can annotate a primary key attribute with @GeneratedValue and set the strategy to GenerationType.UUID. Based on the specification, your ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found