Right, because CASCADE is set for “FK constraint action” for AddOnGroup.product attribute which corresponds to the @OnDeleteInverse(DeletePolicy.CASCADE)
annotation:
public class AddOnGroup {
// ...
@OnDeleteInverse(DeletePolicy.CASCADE)
@JoinColumn(name = "PRODUCT_ID", nullable = false)
@ManyToOne(fetch = FetchType.LAZY, optional = false)
private Product product;
So Studio has generated a foreign key which tries to delete AddOnGroup record when corresponding Product is deleted. But reference from the join table between AddOnGroup and AddOnProduct prevents the deletion, because its FK has no CASCADE rule.
Perhaps you should add CASCADE rules to the join table. You can do it by adding the following Liquibase changelog:
<?xml version="1.0" encoding="UTF-8"?>
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
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-latest.xsd"
objectQuotingStrategy="QUOTE_ONLY_RESERVED_WORDS">
<changeSet id="1" author="demo">
<dropAllForeignKeyConstraints baseTableName="GDKM_ADD_ON_PRODUCT_ADD_ON_GROUP_LINK"/>
</changeSet>
<changeSet id="2" author="demo">
<addForeignKeyConstraint baseColumnNames="ADD_ON_GROUP_ID" baseTableName="GDKM_ADD_ON_PRODUCT_ADD_ON_GROUP_LINK"
constraintName="FK_GDKADDONPROADDONGRO_ON_ADD_ON_GROUP" referencedColumnNames="ID"
referencedTableName="GDKM_ADD_ON_GROUP"
onDelete="CASCADE"/>
<addForeignKeyConstraint baseColumnNames="ADD_ON_PRODUCT_ID"
baseTableName="GDKM_ADD_ON_PRODUCT_ADD_ON_GROUP_LINK"
constraintName="FK_GDKADDONPROADDONGRO_ON_ADD_ON_PRODUCT" referencedColumnNames="ID"
referencedTableName="GDKM_ADD_ON_PRODUCT"
onDelete="CASCADE"/>
</changeSet>
</databaseChangeLog>
After executing the changelog, Studio will generate another one that will again drop the FKs and recreate them without onDelete="CASCADE"
. You should “Remove and Ignore” all these changesets to get rid of them in the future:
Regards,
Konstantin