---
title: "Mysql生成UUID"
author: "roc08"
date: "2013-01-21T15:33:29Z"
tags: []
categories: ["数据库"]
slug: "mysql-uuid"
draft: false
lastmod: "2013-01-21T15:33:44Z"
id: 1773213
url: "https://roc08.iteye.com/blog/1773213"
---

Hibernate中这样配置主键生成后，mysql中并未指定主键生成机制，使用Navicat通过sql语句insert数据时仍需指定Id，

```java
INSERT INTO g_distinct VALUES ( replace(uuid(),'-',''),'110101','东城区','110100');
```



```java
   
    @Id
    @GenericGenerator(name = "generator", strategy = "uuid.hex")
    @GeneratedValue(generator = "generator")
    @Column(name = "LOCATION_ID", length = 40)
    public String getLocationId() {
        return locationId;
    }

```