gpt4 book ai didi

java - Hibernate 不会自动创建表

转载 作者:可可西里 更新时间:2023-11-01 07:57:56 24 4
gpt4 key购买 nike

我有使用 Hibernate/Spring/MySQL 的 Maven 项目。我有基本实体,我希望 Hibernate 自动创建表,但 Hibernate 不创建任何表。也没有抛出异常,所以我不知道这里出了什么问题。

应用程序属性:

# ===============================
# = DATA SOURCE
# ===============================
spring.datasource.url = jdbc:mysql://localhost:3306/task
spring.datasource.username = root
spring.datasource.password = 12345678
spring.datasource.testWhileIdle = true
spring.datasource.validationQuery = SELECT 1

# ===============================
# = JPA / HIBERNATE
# ===============================
spring.jpa.show-sql = true
spring.jpa.hibernate.ddl-auto = create
spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQLDialect
spring.datasource.driver-class-name = com.mysql.jdbc.Driver
spring.jpa.properties.hibernate.format_sql = true
spring.jpa.properties.hibernate.id.new_generator_mappings = true
logging.level.org.hibernate.SQL=DEBUG
logging.level.org.hibernate.type.descriptor.sql.BasicBinder=TRACE
spring.datasource.tomcat.max-wait=20000
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=20
spring.datasource.tomcat.min-idle=15
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.time-between-eviction-runs-millis=3600000
spring.datasource.tomcat.validation-query=SELECT 1

用户.java:

package com.example.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.Table;

import lombok.Data;

@Entity
@Table(name = "user")
@Data
public class User {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private int id;

@Column(name = "telegramId")
private Integer telegramId;

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

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

@OneToMany(
mappedBy = "user",
cascade = CascadeType.ALL,
orphanRemoval = true
)
private List<Message> msg = new ArrayList<>();
}

在 User.java 中我也使用了 lombok。有什么建议么?谢谢你。

最佳答案

我找到了一个解决方案。问题是 Application.java 位于 com.example.BotApp. 包中,现在位于 com.example. 中。我不知道,但不知何故它有所帮助。

关于java - Hibernate 不会自动创建表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50774085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com