Closed ksilz closed 5 years ago
Just to say that the problem is still there
2020-07-10 21:34:09.500 DEBUG 79728 --- [ restartedMain] c.devsparkle.config.CacheConfiguration : Starting HazelcastCacheManager 2020-07-10 21:34:10.314 ERROR 79728 --- [ store-task-1] liquibase.changelog.ChangeSet : Change Set config/liquibase/changelog/20200710202847_added_entity_Customer.xml::20200710202847-1-data::jhipster failed. Error: org.h2.jdbc.JdbcBatchUpdateException: Unique index or primary key violation: "PUBLIC.UX_CUSTOMER_USER_ID_INDEX_5 ON PUBLIC.CUSTOMER(USER_ID) VALUES 2"; SQL statement: INSERT INTO PUBLIC.customer(id, first_name, last_name, gender, email, phone, address_line_1, address_line_2, city, country, user_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-200] 2020-07-10 21:34:10.319 ERROR 79728 --- [ store-task-1] i.g.j.c.liquibase.AsyncSpringLiquibase : Liquibase could not start correctly, your database is NOT ready: Migration failed for change set config/liquibase/changelog/20200710202847_added_entity_Customer.xml::20200710202847-1-data::jhipster: Reason: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcBatchUpdateException: Unique index or primary key violation: "PUBLIC.UX_CUSTOMER_USER_ID_INDEX_5 ON PUBLIC.CUSTOMER(USER_ID) VALUES 2"; SQL statement: INSERT INTO PUBLIC.customer(id, first_name, last_name, gender, email, phone, address_line_1, address_line_2, city, country, user_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-200]
liquibase.exception.MigrationFailedException: Migration failed for change set config/liquibase/changelog/20200710202847_added_entity_Customer.xml::20200710202847-1-data::jhipster: Reason: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcBatchUpdateException: Unique index or primary key violation: "PUBLIC.UX_CUSTOMER_USER_ID_INDEX_5 ON PUBLIC.CUSTOMER(USER_ID) VALUES 2"; SQL statement: INSERT INTO PUBLIC.customer(id, first_name, last_name, gender, email, phone, address_line_1, address_line_2, city, country, user_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-200] at liquibase.changelog.ChangeSet.execute(ChangeSet.java:646) at liquibase.changelog.visitor.UpdateVisitor.visit(UpdateVisitor.java:53) at liquibase.changelog.ChangeLogIterator.run(ChangeLogIterator.java:83) at liquibase.Liquibase.update(Liquibase.java:202) at liquibase.Liquibase.update(Liquibase.java:179) at liquibase.integration.spring.SpringLiquibase.performUpdate(SpringLiquibase.java:366) at liquibase.integration.spring.SpringLiquibase.afterPropertiesSet(SpringLiquibase.java:314) at org.springframework.boot.autoconfigure.liquibase.DataSourceClosingSpringLiquibase.afterPropertiesSet(DataSourceClosingSpringLiquibase.java:46) at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.initDb(AsyncSpringLiquibase.java:118) at io.github.jhipster.config.liquibase.AsyncSpringLiquibase.lambda$afterPropertiesSet$0(AsyncSpringLiquibase.java:93) at io.github.jhipster.async.ExceptionHandlingAsyncTaskExecutor.lambda$createWrappedRunnable$1(ExceptionHandlingAsyncTaskExecutor.java:78) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: liquibase.exception.DatabaseException: org.h2.jdbc.JdbcBatchUpdateException: Unique index or primary key violation: "PUBLIC.UX_CUSTOMER_USER_ID_INDEX_5 ON PUBLIC.CUSTOMER(USER_ID) VALUES 2"; SQL statement: INSERT INTO PUBLIC.customer(id, first_name, last_name, gender, email, phone, address_line_1, address_line_2, city, country, user_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-200] at liquibase.statement.ExecutablePreparedStatementBase.execute(ExecutablePreparedStatementBase.java:87) at liquibase.executor.jvm.JdbcExecutor.execute(JdbcExecutor.java:117) at liquibase.database.AbstractJdbcDatabase.execute(AbstractJdbcDatabase.java:1276) at liquibase.database.AbstractJdbcDatabase.executeStatements(AbstractJdbcDatabase.java:1258) at liquibase.changelog.ChangeSet.execute(ChangeSet.java:609) ... 13 common frames omitted Caused by: org.h2.jdbc.JdbcBatchUpdateException: Unique index or primary key violation: "PUBLIC.UX_CUSTOMER_USER_ID_INDEX_5 ON PUBLIC.CUSTOMER(USER_ID) VALUES 2"; SQL statement: INSERT INTO PUBLIC.customer(id, first_name, last_name, gender, email, phone, address_line_1, address_line_2, city, country, user_id) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) [23505-200] at org.h2.jdbc.JdbcPreparedStatement.executeBatch(JdbcPreparedStatement.java:1235) at com.zaxxer.hikari.pool.ProxyStatement.executeBatch(ProxyStatement.java:128) at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.executeBatch(HikariProxyPreparedStatement.java) at liquibase.statement.BatchDmlExecutablePreparedStatement.executePreparedStatement(BatchDmlExecutablePreparedStatement.java:65) at liquibase.statement.ExecutablePreparedStatementBase.execute(ExecutablePreparedStatementBase.java:85) ... 17 common frames omitted
2020-07-10 21:34:10.702 DEBUG 79728 --- [ restartedMain] c.d.config.DatabaseConfiguration : H2 database is available on port 18080
Here is my JDL export to generate the project
application {
config {
applicationType monolith
authenticationType jwt
baseName store
blueprints []
buildTool gradle
cacheProvider hazelcast
clientFramework angularX
clientPackageManager npm
clientTheme none
creationTimestamp 1593596133788
databaseType sql
devDatabaseType h2Disk
dtoSuffix DTO
embeddableLaunchScript false
enableHibernateCache true
enableSwaggerCodegen false
enableTranslation true
jhiPrefix jhi
jhipsterVersion "6.10.0"
jwtSecretKey "Zjg1ODZhNmE2ZTk0YTdkZjc1Y2IyOTJmYjU3ZmNlMTM2YmM4OTVhNTc1M2Q3YjdjY2Y0YmQ2MDc1NDMyNDQ0NDBkZjgwNmE0NTBjNmI5NjZkOTA2MWJkMzljYWVkOTc3ZjJhOWFmNzZkOGVjYzczYTJmNTc0MmRjY2JiNTJkYjY="
languages [en]
messageBroker false
nativeLanguage en
otherModules []
packageName com.devsparkle
prodDatabaseType mysql
searchEngine false
serverPort 8080
serviceDiscoveryType false
skipClient false
skipServer false
skipUserManagement false
testFrameworks [protractor]
useSass true
websocket spring-websocket
}
entities Customer, Invoice, OrderItem, Product, ProductCategory, ProductOrder, Shipment
}
entity Customer {
firstName String required,
lastName String required,
gender Gender required,
email String required pattern(/^[^@\s]+@[^@\s]+\.[^@\s]+$/),
phone String required,
addressLine1 String required,
addressLine2 String,
city String required,
country String required
}
entity Invoice {
date Instant required,
details String,
status InvoiceStatus required,
paymentMethod PaymentMethod required,
paymentDate Instant required,
paymentAmount BigDecimal required,
code String required
}
entity OrderItem {
quantity Integer required min(0),
totalPrice BigDecimal required min(0),
status OrderItemStatus required
}
entity Product {
name String required,
description String,
price BigDecimal required min(0),
size Size required,
image ImageBlob
}
entity ProductCategory {
name String required,
description String
}
entity ProductOrder {
placedDate Instant required,
status OrderStatus required,
code String required
}
entity Shipment {
trackingCode String,
date Instant required,
details String
}
enum Gender {
MALE,
FEMALE,
OTHER
}
enum InvoiceStatus {
PAID,
ISSUED,
CANCELLED
}
enum PaymentMethod {
CREDIT_CARD,
CASH_ON_DELIVERY,
PAYPAL
}
enum OrderItemStatus {
AVAILABLE,
OUT_OF_STOCK,
BACK_ORDER
}
enum Size {
S,
M,
L,
XL,
XXL
}
enum OrderStatus {
COMPLETED,
PENDING,
CANCELLED
}
relationship OneToOne {
Customer{user(login) required} to User
}
relationship OneToMany {
ProductOrder{invoice} to Invoice{order(code) required},
ProductOrder{orderItem} to OrderItem{order(code) required},
ProductCategory{product} to Product{productCategory(name)},
Customer{order} to ProductOrder{customer(email) required},
Invoice{shipment} to Shipment{invoice(code) required}
}
relationship ManyToOne {
OrderItem{product(name) required} to Product
}
paginate Customer, Invoice, OrderItem, Product, ProductOrder, Shipment with pagination
service Customer, Invoice, OrderItem, Product, ProductCategory, ProductOrder, Shipment with serviceClass
jhipster --version 6.10.0 java --version openjdk 11.0.7 2020-04-14 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.7+10) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.7+10, mixed mode)
<?xml version="1.0" encoding="utf-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.9.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<property name="autoIncrement" value="true"/>
<!--
Added the entity Customer.
-->
<changeSet id="20200710202847-1" author="jhipster">
<createTable tableName="customer">
<column name="id" type="bigint" autoIncrement="${autoIncrement}">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="first_name" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="last_name" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="gender" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="email" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="phone" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="address_line_1" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="address_line_2" type="varchar(255)">
<constraints nullable="true" />
</column>
<column name="city" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="country" type="varchar(255)">
<constraints nullable="false" />
</column>
<column name="user_id" type="bigint">
<constraints unique="true" nullable="false" uniqueConstraintName="ux_customer_user_id" />
</column>
<!-- jhipster-needle-liquibase-add-column - JHipster will add columns here -->
</createTable>
</changeSet>
<changeSet id="20200710202847-1-relations" author="jhipster">
</changeSet>
<!-- jhipster-needle-liquibase-add-changeset - JHipster will add changesets here -->
<!--
Load sample data generated with Faker.js
- This data can be easily edited using a CSV editor (or even MS Excel) and
is located in the 'src/main/resources/config/liquibase/fake-data' directory
- By default this data is applied when running with the JHipster 'dev' profile.
This can be customized by adding or removing 'faker' in the 'spring.liquibase.contexts'
Spring Boot configuration key.
-->
<changeSet id="20200710202847-1-data" author="jhipster" context="faker">
<loadData
file="config/liquibase/fake-data/customer.csv"
separator=";"
tableName="customer">
<column name="id" type="numeric"/>
<column name="first_name" type="string"/>
<column name="last_name" type="string"/>
<column name="gender" type="string"/>
<column name="email" type="string"/>
<column name="phone" type="string"/>
<column name="address_line_1" type="string"/>
<column name="address_line_2" type="string"/>
<column name="city" type="string"/>
<column name="country" type="string"/>
<column name="user_id" type="numeric"/>
<!-- jhipster-needle-liquibase-add-loadcolumn - JHipster (and/or extensions) can add load columns here -->
</loadData>
</changeSet>
</databaseChangeLog>
id;first_name;last_name;gender;email;phone;address_line_1;address_line_2;city;country;user_id
1;Chelsey;Wyman;OTHER;"z*@7.=>hG<Z";014-991-5975 x53760;Tennessee relationships Ball;full-range;Parkerfort;Uzbekistan;1
2;Thalia;Buckridge;MALE;"b@*'X(].k^|";(832) 385-8607;violet Compatible primary;Credit Card Account;New Dalestad;Ukraine;2
3;Maxine;Gibson;OTHER;"w0]@MYsVUi.+b[";(301) 227-7081 x51545;Georgia;Robust ivory Ports;Port Darienbury;South Georgia and the South Sandwich Islands;2
4;Levi;Lemke;FEMALE;"5'-II@>'5Gy`.L";1-488-295-4126 x80618;high-level fuchsia;International;East Alec;Colombia;1
5;Olen;Brekke;MALE;"kbs@[v6S.oz";466.499.8661 x875;Dynamic Meadows;Brand system-worthy Soft;Leuschkeville;India;2
6;Laurence;Bartoletti;OTHER;"efoj2@{|*:.g%t";801.137.7575 x4467;fuchsia;Fantastic invoice;Morarview;Estonia;1
7;Martine;Abshire;FEMALE;"M/'@$ZzkOi.5L}<";572-425-8749 x654;array Awesome;foreground Refined grey;Lake Zita;Paraguay;2
8;Johan;Wolff;OTHER;"lwrwoz@(FSQ9.X,}9V";1-479-070-4986 x050;Sao Tome and Principe;Solutions;Port Raoul;Isle of Man;2
9;Alexa;Kiehn;FEMALE;"#J@08uP5\.`IMKnV";1-757-965-1677 x985;Frozen embrace sexy;silver;Morarstad;Armenia;2
10;Breana;Gleichner;OTHER;"e@bLE+sB.]HQq";1-094-233-8136 x35665;Unions Shoes;Cape Verde Escudo;Kamrynberg;Uruguay;2
@devsparkles Yes the issue is there but this is something developers need to fix the CSV data manually. Please check https://github.com/jhipster/generator-jhipster/issues/9579 and https://github.com/jhipster/generator-jhipster/issues/9579#issuecomment-519842714
Overview of the issue
For my Angular / H2 monolith, jHipster generates fake data which doesn't honor the
unique
constraint on myShipment
entity. Liquibase fails to load the fake data for this entity.order_id
column (second from right) has4
three times and9
twice.Here is the stacktrace:
Motivation for or Use Case
I have a valid JDL file that jHipster imports without reporting an error. However, the generated fake data is wrong and prevents the application from running correctly.
Reproduce the error
./gradlew
to start the application.Related issues
9721: This bug is about wrong columns in the fake data. However, I actually mentioned the unique violation described here in a comment.
Suggest a Fix
JHipster Version(s)
JHipster 6.1.2, Java 11
JHipster configuration
JHipster configuration, a
.yo-rc.json
file generated in the root folder.yo-rc.json file
JDL for the Entity configuration(s)
entityName.json
files generated in the.jhipster
directoryJDL entity definitions
Environment and Tools
openjdk version "11.0.3" 2019-04-16 OpenJDK Runtime Environment AdoptOpenJDK (build 11.0.3+7) OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.0.3+7, mixed mode)
git version 2.22.0
node: v10.15.3
npm: 6.9.0
yeoman: 2.0.6
Docker version 18.09.2, build 6247962
docker-compose version 1.23.2, build 1110ad01
Entity configuration(s)
entityName.json
files generated in the.jhipster
directoryShipment.json
Browsers and Operating System
macOS Mojave 10.14.4, Safari