Different representation of UUID in Java Hibernate and SQL Server

后端 未结 3 1696
星月不相逢
星月不相逢 2020-12-03 21:26

I am trying to map a UUID column in POJO to SQL Server table column using Hibernate.

The annotations are applied as follows:

@Id
@Genera         


        
3条回答
  •  情话喂你
    2020-12-03 22:04

    Microsoft databases use GUIDs. It is Microsoft's implementation of the UUID standard.

    This being said, you should use the guid generator.

    @Id
    @GenericGenerator(name = "generator", strategy = "guid", parameters = {})
    @GeneratedValue(generator = "generator")
    public String getId() {
        return id;
    }
    

    guid uses a database-generated GUID string on MS SQL Server and MySQL.

    Also, have you set SQLServer2012Dialect? This also might solve some future issues.

提交回复
热议问题