gpt4 book ai didi

java - hibernate中的@GenerateValue(strategy = IDENTITY)在部署时不会生成relation(table)

转载 作者:行者123 更新时间:2023-11-29 23:10:08 25 4
gpt4 key购买 nike

我的代码中有以下内容:

@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
private Long id;

而且,我注意到,当我有 @GenerateValue 时,它根本不会生成我的 MySql 表,但如果没有该注释,它会生成相应的表。

我应该检查哪些关键点?

最佳答案

这非常棘手,因为您可能认为您已经正确定义了 hibernate 的所有属性,并且添加了 @GenerateValue 注释,从而导致 SQL Gram-mer 错误。然而,我能够通过更仔细地探索 hibernate 属性来解决这个问题。具体在 hibernate 配置中查找以下属性。属性名称=“hibernateProperties”>

            hibernate.dialect=${hibernate.dialect}
hibernate.hbm2ddl.auto=create

对于 hibernate.dialect --> 你应该有 org.hibernate.dialect.MySQL5InnoDBDialect但您可能会看到,它还在 MySQL 数据库中生成 -> org.hibernate.dialect.SQLServerDialect 的表,这使您得出结论:您已正确设置 hibernate 属性。如果您的任何元数据注释产生语法错误,我强烈建议您检查 hibernate 属性

谢谢

关于java - hibernate中的@GenerateValue(strategy = IDENTITY)在部署时不会生成relation(table),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28121619/

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