Foreign key constraint fails (jdbc, jpa, mysql)
See original GitHub issueHello
Maybe this is a configuration problem on my end, but I tried it based on the sample ‘lightmin-jpa-application’ as well. The following describes what I did with the lightmin-jpa-application (all in ApplicationConfiguration.java):
- Instead of a H2 in memory database, I changed the datasource(s) to
HikariDataSource dataSource = new HikariDataSource();
dataSource.setDriverClassName("org.mariadb.jdbc.Driver");
(...)
- Changed the database from H2 to Mysql:
hibernateJpaVendorAdapter.setDatabase(Database.MYSQL);
- Added the jdbc configuration repository annotation:
@EnableLightminJdbcConfigurationRepository
Of course I had to add the respective dependencies in the pom.
After I created the required tables I was able to start the application just fine. However, when I try to add a new scheduler (cron) the operation fails with the following exception:
PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_CONFIGURATION_VALUE (job_configuration_id,value_key, configuration_value) VALUES (?,?,?)]; (conn=603) Cannot add or update a child row: a foreign key constraint fails (
testlightmin
.batch_job_configuration_value
, CONSTRAINTbatch_job_configuration_value_ibfk_1
FOREIGN KEY (job_configuration_id
) REFERENCESbatch_job_configuration
(job_configuration_); nested exception is java.sql.BatchUpdateException: (conn=603) Cannot add or update a child row: a foreign key constraint fails (
testlightmin.
batch_job_configuration_value, CONSTRAINT
batch_job_configuration_value_ibfk_1FOREIGN KEY (
job_configuration_id) REFERENCES
batch_job_configuration(
job_configuration_)
The autoincrement value on BATCH_JOB_CONFIGURATION.job_configuration_id
does increase, but no record is ever stored. Could there be a problem with a transaction, or did I miss something?
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (5 by maintainers)
Top GitHub Comments
Hi, versions 1.0.2 and 2.0.2 are released and they are containing the fix.
Hi @kevinzogg, thank you very much. I will create a 2.0.2 release as soon as possible which includes the fix.
Greetings,
Marcel