Using UUID As Entity Primary Key In Jakarta EE 10
Originally published on 23 Mar 2023
Last updated on 23 Mar 2023
In prior versions of Jakarta EE, the use of UUID as entity ID or database primary key type was a vendor specific feature. So even though you could use it, you had to rely on vendor specific constructs to get the mapping right. With the release of Jakarta EE 10 however, the Jakarta Persistence specification now provides native support for using UUID as entity ID type.
The jakarta.persistence.GenerationType now has a UUID option that indicates to the persistence provider to generate and assign RFC 4122 UUID to the annotated field. The HelloEntity below shows how to use this new feature.
@Entity
public class HelloEntity implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.UUID)
private UUID id;
private String greeting;
}
The strategy parameter of the @GeneratedValue annotation is passed the GenerationType.UUID type. With this, you now have a vendor neutral, portable way to entity IDs to the UUID type.
Read more of our Jakarta EE content:
- A Developer Guide To WebSocket Development On The Jakarta EE Platform
- A Business Guide to NoSQL on the Jakarta EE Platform
- A Business Guide To Cloud Deployment Options For Jakarta EE Applications
Related Posts
Jakarta EE Media & Community Challenge - Winning Entries: Part 4
Published on 19 Dec 2024
by Chiara Civardi
2 Comments
The Jakarta EE Media and Community Challenge initiated by Payara celebrates the innovation and creativity that thrives within the Jakarta EE community. This global competition invited developers, technical writers and technology enthusiasts to ...
Virtual Payara Conference is this week! See the Agenda Highlights
Published on 09 Dec 2024
by Dominika Tasarz
0 Comments
Virtual Payara Conference - find out more and register here - is a two-day, free event that brings together industry leaders, developers, and innovators to explore the latest advancements and strategic insights in the world of Java and Jakarta ...