UUID does not have hyphens in between

倾然丶 夕夏残阳落幕 提交于 2021-02-05 05:34:05

问题


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.

来源:https://stackoverflow.com/questions/62568885/uuid-does-not-have-hyphens-in-between

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!