Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8070815
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:30:55+00:00 2026-06-05T13:30:55+00:00

I am trying to delete a child record when parent is deleted. There is

  • 0

I am trying to delete a child record when parent is deleted. There is no column in the parent table that refers to child. The child refers to parent in a one-to-one optional relationship.

When parent is being deleted, a constraint is thrown due to the fact relationship still exists. If I add the set relationship to the child side, it does not help. Hibernate does not delete the child record since I am guessing, child record was never fetched.

Is there a way to delete child records short of doing it in an interceptor ? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:30:57+00:00Added an answer on June 5, 2026 at 1:30 pm

    I will provide the example to a similar situation, applying which to your situation will solve the problem.

    Lets assume that Employee has a Department_ID in it’s table, and Department does not have any column referencing Employee_ID.

    We associate employee with a department using join column. This way we get uni-directional association.

    public class Employee {
    
        @OneToOne
        @JoinColumn(name = "DEPARTMENT_ID")
        private Department department;
    }
    

    Next we associate department with employee by marking association with mappedBy attribute. It references the owning field of the association on the Employee side. This way we get bi-directional association.

    public class Department {
    
        @OneToOne(mappedBy = "department", cascade = CascadeType.ALL)
        private Employee employee;
    } 
    

    Marking association with CascadeType.ALL will include CascadeType.REMOVE, which will cascade to Employee on remove operation. Now, removing department, will remove employee along with it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to remove a child entity from a parent collection navigation property. There
I have a parent child relationship between 2 classes Parent @Entity @Table(name = PARENT)
I'm trying to clear a collection in a parent/child relationship by either clearing the
I am trying to delete the child element in the dom from its parent
I am trying to create a table which captures parent child relationships, like a
I´m trying to map a list using NHibernate that is part of a parent-child
I am trying to delete part of a string that does not match my
I am trying to delete a list of entries form my table corresponding to
I'm using Entity Framework 4 and have a one-to-many relationship between a parent and
I have the following two mySQL tables with the 'child' table having a DELETE

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.