码迷,mamicode.com
首页 > 编程语言 > 详细

springdata jpa自动建表

时间:2018-11-14 12:26:29      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:driver   get   ted   rate   time   getpass   rac   classname   com   

application.properties文件内容为:

spring.datasource.driverClassName=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/demo?characterEncoding=utf-8&serverTimezone=GMT%2B8
spring.datasource.username=root
spring.datasource.password=root
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

自动建表实体对象为:

package com.ysoo.entity;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.io.Serializable;

@Entity
@Table(name = "t_user")
public class User implements Serializable {

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO, generator = "uuid")
    @GenericGenerator(name = "uuid", strategy = "uuid2")
    @Column(name = "id")
    private String id;

    @Column(name = "name")
    private String name;

    @Column(name = "password")
    private String password;

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }
}
@GeneratedValue和@GenericGenerator注解需要如上配置 否则会出现建表不成功或者生成hibernate_sequence多余的表

 

springdata jpa自动建表

标签:driver   get   ted   rate   time   getpass   rac   classname   com   

原文地址:https://www.cnblogs.com/rain-in-summer/p/9956986.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!