gpt4 book ai didi

java - Hibernate 无法创建表 hibernate_sequences

转载 作者:行者123 更新时间:2023-11-29 06:07:17 24 4
gpt4 key购买 nike

hibernate 版本:

<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.4.Final</version>
</dependency>

ExportDB.java:

public class ExportDB {
public static void main(String[] args) {
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().configure().build();
Metadata metadata = new MetadataSources(serviceRegistry).buildMetadata();
SchemaExport schemaExport = new SchemaExport();
schemaExport.create(EnumSet.of(TargetType.DATABASE), metadata);
}
}

运行 ExportDB.java:

2016-11-19 00:22:12,845 WARN [org.hibernate.orm.connections.pooling] - HHH10001002: Using Hibernate built-in connection pool (not for production use!)
Hibernate: drop table if exists hibernate_sequences
Hibernate: drop table if exists user
Hibernate: create table hibernate_sequences (sequence_name varchar(255) not null, sequence_next_hi_value bigint, primary key (sequence_name))
Hibernate: create table user (id bigint not null, balance decimal(20,4) default 0.00, createTime time, displayName varchar(64), password varchar(64), username varchar(64), primary key (id))
Hibernate: alter table user add constraint UK_7kuje5s4lbyq9qyv1r9ecm2it unique (username)

数据库:

MariaDB [cms]> show tables;
+----------------+
| Tables_in_cms |
+----------------+
| investor |
+----------------+
1 row in set (0.00 sec)

当我使用打印的 SQL 创建 hibernate_sequences 时:

MariaDB [cms]> create table hibernate_sequences (sequence_name varchar(255) not null, next_val bigint, primary key (sequence_name));
ERROR 1071 (42000): Specified key was too long; max key length is 767 bytes

如何让 ExportDB.java 可以创建 hibernate_sequences

最佳答案

您正在使用 utf8mb4,对吗?您使用的是 5.6 或更早版本?

计划 A:升级到 5.7。

B 计划:将 255 减少到 191 或更少。 (你真的需要 255 吗??)

方案C:改为CHARACTER SET utf8(假设你不需要Emoji或中文)

计划 D:通常“序列”是数字。如果是这种情况,INT UNSIGNEDBIGINT UNSIGNED 将无法工作吗?

关于java - Hibernate 无法创建表 hibernate_sequences,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40682355/

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