- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在使用 Hibernate 时遇到问题。
我正在通过 Flyway 迁移创建表。
下面显示了部分初始迁移脚本的片段。
脚本确实运行了(我可以在 Debug模式下看到它)。
在脚本运行之后,Hibernate 的 validator 似乎没有使用我通过 javax.persistence
提供的实体的表名。 .
为了清楚起见,这里有一些遗漏的实体:
import javax.persistence.*;
@Entity
@Table(name = "IngredientCategories")
public class IngredientCategory implements IEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
@Column(nullable = false, length = 128)
private String name;
...
}
CREATE TABLE `IngredientCategories` (
`id` bigint NOT NULL AUTO_INCREMENT,
`description` varchar(255) DEFAULT NULL,
`name` varchar(128) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
查看日志,运行 Flyway 迁移,然后
之后 我收到 hibernate 验证错误。
2020-10-24 11:22:11.952 DEBUG 91583 --- [ main] o.f.core.internal.command.DbMigrate : Successfully completed migration of schema `test` to version 1 - init
2020-10-24 11:22:11.961 DEBUG 91583 --- [ main] o.f.c.i.s.JdbcTableSchemaHistory : Schema History table `test`.`flyway_schema_history` successfully updated to reflect changes
2020-10-24 11:22:11.970 INFO 91583 --- [ main] o.f.core.internal.command.DbMigrate : Successfully applied 1 migration to schema `test` (execution time 00:00.107s)
2020-10-24 11:22:11.972 DEBUG 91583 --- [ main] org.flywaydb.core.Flyway : Memory usage: 82 of 354M
2020-10-24 11:22:12.088 INFO 91583 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [name: default]
2020-10-24 11:22:12.125 INFO 91583 --- [ main] org.hibernate.Version : HHH000412: Hibernate ORM core version 5.4.20.Final
2020-10-24 11:22:12.237 INFO 91583 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.1.0.Final}
2020-10-24 11:22:12.350 INFO 91583 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.MySQL8Dialect
2020-10-24 11:22:12.998 WARN 91583 --- [ main] s.c.a.AnnotationConfigApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [ingredient_categories]
2020-10-24 11:22:12.998 INFO 91583 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown initiated...
2020-10-24 11:22:13.420 INFO 91583 --- [ main] com.zaxxer.hikari.HikariDataSource : HikariPool-1 - Shutdown completed.
2020-10-24 11:22:13.428 INFO 91583 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-10-24 11:22:13.434 ERROR 91583 --- [ main] o.s.boot.SpringApplication : Application run failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: [PersistenceUnit: default] Unable to build Hibernate SessionFactory; nested exception is org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [ingredient_categories]
我无法确定这是 hibernate 问题、Flyway 问题还是测试问题。
@SpringBootTest
@Testcontainers
class DataApplicationTests {
@Test
void contextLoads() {
}
}
我环顾四周,可以看到很多人在 Spring 2x 之前遇到了一个问题,即在 Flyway 生成模式之前验证表... .
Schema-validation: missing table [ingredient_categories]
所以它似乎没有使用 javax.containt.Table
@Table(name="IngredientCategories")
运行和构建上下文/bean 时的注释。
#=========INTEGRATION TESTS========#
## Using TestContainers
spring.datasource.url=jdbc:tc:mysql:8.0.22:///
# Validate Schema
spring.jpa.hibernate.ddl-auto = validate
logging.level.org.flywaydb=DEBUG
最佳答案
来自官方 doc
By default, Spring Boot configures the physical naming strategy withSpringPhysicalNamingStrategy. This implementation provides the sametable structure as Hibernate 4: all dots are replaced by underscoresand camel casing is replaced by underscores as well. By default, alltable names are generated in lower case, but it is possible tooverride that flag if your schema requires it.
For example, a TelephoneNumber entity is mapped to thetelephone_number table.
IngredientCategories
变成了
ingredient_categories
.对于数据库表名一般约定使用蛇形大小写。您可以在蛇案例中创建带有名称的表
CREATE TABLE `ingredient_categories`
或者,如果您更喜欢使用 Hibernate 5 的默认值,请设置以下属性:
spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl
那么你的表名仍然是
IngredientCategories
如
@Table
中所述注解。详情
Hibernate 5 Naming Strategy Configuration
关于java - 在启动时进行 DDL 验证时,Hibernate 不使用 @Table。使用 Flyway 和 TestContainers,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64512485/
是 Flyway适合在支持多个数据库的应用程序中实现吗? 我们不知道我们的客户在使用什么——可能是 MySQL、Postgres 或 Oracle。我们还可以使用 Flyway 为新版本的应用程序迁移
只想知道正在使用 flyway 的人是否得到了这个 > 版本设置为 0。 它突然开始出现在我的元数据表上,我不确定它从哪里来,也不知道如何运行 mugrates 而不会再次出现 最佳答案 这意味着 f
大家好! :) 我一直在看 Flyway,但我不确定如何使用它。就我而言,我有一个实体模型(使用 JPA 进行注释),对我而言,每次调用“迁移”并生成迁移文件时,FlyWay 都可以找出模型上的更改,
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 4 年前。 Improve this ques
场景:我有两个数据库。 第一个数据库是用于测试的空白数据库。我基本上运行 flyway:migrate 并使用完整的模式构建数据库,然后针对该空白数据库运行我的集成测试。在运行测试之前插入集成测试所需
我刚刚遇到了以下情况: 测试服务器当前正在运行 Flyway,版本为 1 (V1)。每当在 develop 分支上推送任何内容时,测试服务器都会自动更新(包括 Flyway 脚本)。 开发人员决定开始
我有一个项目,其数据库由 Flyway 在严格验证模式下管理。 我的迁移文件如下所示: V1.0__init.sql V11.0__even_better.sql V2.0__update.sql V
我们从项目开始就没有使用过 Flyway。我们处于先进的发展状态。专家评审建议在我们的项目中使用 Flyway。 问题是我们也将部分服务(微服务)移到了另一个测试环境中。 正确实现 Flyway 的最
我正在评估在我的项目中使用的 Flyway。我们当前的 SQL 脚本包含诸如 URL 之类的占位符,这些占位符将根据环境(dev、qa、prod)具有不同的域名。 具体来说,我们可能有 INSERT
我有一个名为V1_7__a_and_c.sql的flyway迁移脚本,但我意识到它不是关于“a”和“c”,而是关于“a”和“b”,所以该文件的正确名称实际上是 V1_7__a_and_b.sql。 我
我已将产品交付给客户。现在我已经升级了产品,其中包括对数据库的更改。 客户想要升级产品。现在 Flyway 将帮助客户数据从旧版本迁移到新版本。如果这是一个有效的用例,请告诉我。 flyway 文档仅
flyway 是否支持每个环境有条件地执行脚本? 例如,如果我有测试数据,是否可以创建一个仅在 env 配置为测试时加载的测试数据脚本文件夹? 最佳答案 对于 future 的访问者,这是针对特定于数
如果 flyway 在运行时最终会执行任何迁移,我们的部署系统想知道,因为它需要执行一组不同于没有数据库迁移的操作(如果有迁移,那么集群中的所有服务器都被关闭,然后一台服务器启动并执行迁移,然后将其余
我遇到以下问题: org.flywaydb.core.api.FlywayException: Validate failed: Detected applied migration not reso
我一直在阅读一篇关于 Flyway 的博客文章,名为 Lessons Learned Using Flyway DB with Distributed Version Control .作者的建议之一
因此,由于某些要求,我在升级 flyway 版本后了解到,flyway-core-2.2 为 Flyway 占位符引入了一些验证。 现在,占位符语法的约定在大多数库中都是 ${name} 统一的。在我
因此,只是探索使用 flyway 使用 Athena 提供的 JDBC 驱动程序针对 Amazon Athena 维护我的 DDL 语句的可能性,Athena 仅支持 CREATE 语句(hive D
我已经成功配置了 spring boot 和一个可以工作的新项目带飞路 使用 Postgres 数据库从 0001.0 版本迁移到 0008.0 我已经在本地手动更改了脚本但是flyway 迁移失败。
我目前正在使用 Flyway 命令行工具来管理我们的脚本,这些脚本将通过我们的 CI 构建服务器触发的发布过程来调用。 问题是我有 274 个可重复的迁移,涵盖包规范、包主体、函数、过程、 View
在 Flyway 中,我无法使用定义精确有序的迁移脚本集的文件(类似于 Liquibase approach )。 除了实现我自己的 MigrationResolver 之外,还有其他方法吗? 最佳答
我是一名优秀的程序员,十分优秀!