← All posts

Spring Boot + PostgreSQL + UUID String

Want your primary key to be a UUID string instead of a number? With PostgreSQL it’s really easy. Just tell your entity to use the UUID2 generator, like this:

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

Done!