1

Hibernate cascade remove doesn't remove child when deleting parent. causing this error:

ORA-02292: violated integrity constraint (owner.constraintname)- child record found. 

Here are my entities:

@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

and:

@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

I want to delete any child FlightMapRegionI18n records when deleting the parent FlightMapRegion record.

Note that these tables are not connected via id, they are connected like this:

FOREIGN KEY (FLIGHT_MAP_REGION_CODE) 
REFERENCES FLIGHT_MAP_REGION (CODE)

And I don't want to add ON DELETE CASCADE on database level. I want to achive this programmatically in java.

kk_123
  • 11
  • 1
  • Is there any property `owner` in one of your objects? – Jens Jul 28 '15 at 08:57
  • See this http://stackoverflow.com/questions/27667349/integrity-constraint-violated-child-record-found-java-oracle-hibernat – Subodh Joshi Jul 28 '15 at 08:58
  • @Jens Can you please explain what does `owner` property mean? Do you mean owner relationship like `mappedBy` ? – kk_123 Jul 28 '15 at 10:51
  • I mean an attribute in one object that has the name owner. – Jens Jul 28 '15 at 10:52
  • no, there isn't an owner attribute. – kk_123 Jul 28 '15 at 11:02
  • I searched your problem and found a similar problem on http://www.coderanch.com/t/456563/ORM/databases/Hibernate-strange-behavior Could you change your Link to Set as private Set flightMapRegionI18ns; And also you may want to check this solution http://stackoverflow.com/questions/549961/hibernate-removing-item-from-a-list-does-not-persist – Burak Keceli Jul 28 '15 at 11:55

0 Answers0