Есть две сущности:
Recipe
RecipeLine
DDL
create table RECIPE_RECIPE (
ID bigint not null,
UUID varchar(36) not null,
CREATE_TS timestamp,
CREATED_BY varchar(50),
--
NAME varchar(255) not null,
DESCRIPTION varchar(1024),
--
primary key (ID)
)^
create table RECIPE_RECIPE_LINE (
ID bigint not null,
UUID varchar(36) not null,
CREATE_TS timestamp,
CREATED_BY varchar(50),
--
RECIPE_ID bigint,
PRODUCT_ID bigint not null,
QUANTITY decimal(19, 3) not null,
--
primary key (ID)
)^
-- constraints
alter table RECIPE_RECIPE_LINE add constraint FK_RECIPE_RECIPE_LINE_RECIPE_ID foreign key (RECIPE_ID) references RECIPE_RECIPE(ID)^
alter table RECIPE_RECIPE_LINE add constraint FK_RECIPE_RECIPE_LINE_PRODUCT_ID foreign key (PRODUCT_ID) references RECIPE_PRODUCT(ID)^
-- indexes
create index IDX_RECIPE_RECIPE_LINE_PRODUCT on RECIPE_RECIPE_LINE (PRODUCT_ID)^
create index IDX_RECIPE_RECIPE_LINE_RECIPE on RECIPE_RECIPE_LINE (RECIPE_ID)^
Source:
/*
* Copyright (c) 2014 com.company.recipe
*/
package com.company.recipe.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.persistence.Column;
import com.haulmont.cuba.core.entity.BaseLongIdEntity;
import com.haulmont.chile.core.annotations.NamePattern;
import com.haulmont.chile.core.annotations.Composition;
import com.haulmont.cuba.core.entity.annotation.OnDelete;
import com.haulmont.cuba.core.global.DeletePolicy;
import java.util.Set;
import javax.persistence.OneToMany;
/**
*/
@NamePattern("%s|name")
@Table(name = "RECIPE_RECIPE")
@Entity(name = "recipe$Recipe")
public class Recipe extends BaseLongIdEntity {
@Column(name = "NAME", nullable = false)
protected String name;
@Column(name = "DESCRIPTION", length = 1024)
protected String description;
private static final long serialVersionUID = -1778736028777743226L;
@OnDelete(DeletePolicy.CASCADE)
@Composition
@OneToMany(mappedBy = "recipe")
protected Set<RecipeLine> recipeLine;
public void setRecipeLine(Set<RecipeLine> recipeLine) {
this.recipeLine = recipeLine;
}
public Set<RecipeLine> getRecipeLine() {
return recipeLine;
}
public void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setDescription(String description) {
this.description = description;
}
public String getDescription() {
return description;
}
}
/*
* Copyright (c) 2014 com.company.recipe
*/
package com.company.recipe.entity;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.math.BigDecimal;
import javax.persistence.Column;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import com.haulmont.cuba.core.entity.BaseLongIdEntity;
import com.haulmont.cuba.core.entity.annotation.OnDeleteInverse;
import com.haulmont.cuba.core.global.DeletePolicy;
/**
*/
@Table(name = "RECIPE_RECIPE_LINE")
@Entity(name = "recipe$RecipeLine")
public class RecipeLine extends BaseLongIdEntity {
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "RECIPE_ID")
protected Recipe recipe;
@ManyToOne(fetch = FetchType.LAZY, optional = false)
@JoinColumn(name = "PRODUCT_ID")
protected Product product;
@Column(name = "QUANTITY", nullable = false, precision = 19, scale = 3)
protected BigDecimal quantity;
private static final long serialVersionUID = -2655051636914709145L;
public void setProduct(Product product) {
this.product = product;
}
public Product getProduct() {
return product;
}
public void setRecipe(Recipe recipe) {
this.recipe = recipe;
}
public Recipe getRecipe() {
return recipe;
}
public void setQuantity(BigDecimal quantity) {
this.quantity = quantity;
}
public BigDecimal getQuantity() {
return quantity;
}
}
При удалении основной сущности Recipe - выдает сообщение
"SQLIntegrityConstraintViolationException: integrity constraint violation: foreign key no action; FK_RECIPE_RECIPE_LINE_RECIPE_ID table: RECIPE_RECIPE_LINE"
- как будто атрибут on delete = cascade не отрабатывает. В чем может быть причина?