Reputation: 605
Spring Boot 1.5.8 and Java 8 here. I've followed all the Spring Boot & Liquibase guides and I can't seem to get Liquibase to work.
Here is a link to a GitHub repo for reproducing the issue exactly, but here's the scoop:
I have the following MySQL v8 database that gets created like so ahead of time (before the app runs):
CREATE DATABASE IF NOT EXISTS troubleshooting_db CHARACTER SET utf8 COLLATE utf8_general_ci;
I have the following src/main/resources/db/changelog
files:
db.changelog-master.yaml:
===
databaseChangeLog:
- include:
file: db/changelog/1-setup.sql
1-setup.sql:
===
--liquibase formatted sql
--changeset troubleshooting:1 dbms:mysql
-- LOOKUPS
CREATE TABLE IF NOT EXISTS metric_range_categories (
metric_range_category_id BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
metric_range_category_ref_id VARCHAR(36) NOT NULL,
metric_range_category_name VARCHAR(250) NOT NULL,
metric_range_category_label VARCHAR(250) NOT NULL,
metric_range_category_description VARCHAR(500) NOT NULL,
CONSTRAINT pk_metric_range_categories PRIMARY KEY (metric_range_category_id),
INDEX idx_metric_range_categories_metric_range_category_ref_id (metric_range_category_ref_id),
INDEX idx_metric_range_categories_metric_range_category_label (metric_range_category_label),
CONSTRAINT uc_metric_range_categories_metric_range_category_ref_id UNIQUE (metric_range_category_ref_id),
CONSTRAINT uc_metric_range_categories_metric_range_category_name UNIQUE (metric_range_category_name),
CONSTRAINT uc_metric_range_categories_metric_range_category_label UNIQUE (metric_range_category_label)
);
-- Lots of other CREATE TABLE statements down here...
And the following JPA-annotated entity:
@Entity
@Table(name = "metric_range_categories")
@AttributeOverrides({
@AttributeOverride(name = "id", column = @Column(name = "metric_range_category_id")),
@AttributeOverride(name = "refId", column = @Column(name = "metric_range_category_ref_id")),
@AttributeOverride(name = "name", column = @Column(name = "metric_range_category_name")),
@AttributeOverride(name = "label", column = @Column(name = "metric_range_category_label")),
@AttributeOverride(name = "description", column = @Column(name = "metric_range_category_description"))
})
public class MetricRangeCategory extends BaseLookup {
public MetricRangeCategory() {
}
public MetricRangeCategory(Long id, String refId, String name, String label, String description) {
super(id, refId, name, label, description);
}
}
At runtime I get the following exception:
Caused by: org.hibernate.tool.schema.spi.SchemaManagementException: Schema-validation: missing table [metric_range_categories]
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.validateTable(SchemaValidatorImpl.java:67)
at org.hibernate.tool.schema.internal.SchemaValidatorImpl.doValidation(SchemaValidatorImpl.java:50)
at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:91)
at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:475)
at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444)
at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:879)
... 29 common frames omitted
So when it starts up, Liquibase does not excute/engage and so Hibernate JPA validation fails because its looking for a table that doesn't exist (because Liquibase never kicked in and did its job!). Any ideas as to where I'm going awry? Why isn't Liquibase kicking in?
Upvotes: 1
Views: 2432
Reputation: 4365
There are 2 different problems in the repo:
Upvotes: 3