Spring Boot + PostgreSQL + UUID String

Natthapon Pinyo
Nov 11, 2020

--

It’s easy to use UUID String as Primary Key when you are using PostgreSQL database.

To archive this, just configure your Entity to use UUID2 generator.

@Id
@GenericGenerator(name = "uuid2", strategy = "uuid2")
@GeneratedValue(strategy = GenerationType.IDENTITY, generator = "uuid2")
@Column(length = 36, nullable = false, updatable = false)
private String id;

Done!

--

--