删除父级时,Hibernate级联删除不会删除子级。 导致此错误:
ORA-02292: violated integrity constraint (owner.constraintname)- child record found.
以下是我的实体:
@Entity
@Table(name = "FLIGHT_MAP_REGION")
@Audited
public class FlightMapRegion extends AbstractBWSModel {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "FLIGHT_MAP_REGION_ID_GENERATOR", sequenceName = "SEQ_FLIGHT_MAP_REGION", allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FLIGHT_MAP_REGION_ID_GENERATOR")
private Long ID;
@Column(name = "CODE")
private String code;
// bi-directional one-to-many association to FlightMapRegionI18n
@OneToMany (mappedBy = "flightMapRegion", fetch = FetchType.EAGER, cascade=CascadeType.REMOVE, orphanRemoval=true)
@Fetch(value = FetchMode.SUBSELECT)
@NotAudited
private List<FlightMapRegionI18n> flightMapRegionI18ns;
//getters&setters
和
@Entity
@Table(name = "FLIGHT_MAP_REGION_I18N")
@Audited
public class FlightMapRegionI18n extends AbstractBWSModel implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@SequenceGenerator(name = "FLIGHT_MAP_REGION_I18N_ID_GENERATOR", sequenceName = "SEQ_FLIGHT_MAP_REGION_I18N", allocationSize=1)
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "FLIGHT_MAP_REGION_I18N_ID_GENERATOR")
private Long ID;
@Column(name = "NAME")
private String name;
// bi-directional many-to-one association to flightMapRegion
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "FLIGHT_MAP_REGION_CODE", referencedColumnName="CODE")
@AuditJoinTable
private FlightMapRegion flightMapRegion;
//getters & setters
我想在删除父FlightMapRegion记录时删除任何子FlightMapRegionI18n记录。
请注意,这些表未通过ID连接,它们的连接方式如下:
FOREIGN KEY (FLIGHT_MAP_REGION_CODE)
REFERENCES FLIGHT_MAP_REGION (CODE)
我不想在数据库级别添加ON DELETE CASCADE
。我想在java中以编程方式实现此目的。