UUID does not have hyphens in between

Viewed 1699

Inspired by the suggestion given here - JPA Entity class giving error with 2 @GeneratedValue fields, my question is the OPPOSITE of this - How to generate uuids without dashes

I am using H2 DB and have this in my model:

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Column(name = "id")
    private Long id;

    @Column(name = "useruuid")
    @GeneratedValue(generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid4")
    private UUID userUUID; 

And in my controller it goes like this:

    @PostConstruct
    private void postConstruct() {
        AppUser appUser = new AppUser(1l, UUID.randomUUID());
        appUserJPARepository.save(appUser);
    }

Now when my Spring Boot app starts my H2 DB-Console shows this:

ID      USERUUID  
1       25b9b7f391d94825b349866fe9a9077c

Question: How do I get hyphens in the DB? So that my uuid in the DB will be - 25b9b7f3-91d9-4825-b349-866fe9a9077c

I fiddled with @GenericGenerator(name = "uuid4", strategy = "uuid4") uuid(1) to uuid5 but got the same result. What is going on here and what I am doing wrong or what should I do to get hyphens in the DB? Any help or related info/links relevant to this will be greatly appreciated.

0 Answers
Related