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 541587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:21:30+00:00 2026-05-13T10:21:30+00:00

I have a problem with a simple @OneToMany mapping between a parent and a

  • 0

I have a problem with a simple @OneToMany mapping between a parent and a child entity. All works well, only that child records are not deleted when I remove them from the collection.

The parent:

@Entity
public class Parent {
    @Id
    @Column(name = "ID")
    private Long id;

    @OneToMany(cascade = {CascadeType.ALL}, mappedBy = "parent")
    private Set<Child> childs = new HashSet<Child>();

 ...
}

The child:

@Entity
public class Child {
    @Id
    @Column(name = "ID")
    private Long id;

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name="PARENTID", nullable = false)
    private Parent parent;

  ...
}

If I now delete and child from the childs Set, it does not get deleted from the database. I tried nullifying the child.parent reference, but that did not work either.

The entities are used in a web application, the delete happens as part of an Ajax request. I don’t have a list of deleted childs when the save button is pressed, so I can’t delete them implicitly.

  • 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-05-13T10:21:31+00:00Added an answer on May 13, 2026 at 10:21 am

    JPA’s behaviour is correct (meaning as per the specification): objects aren’t deleted simply because you’ve removed them from a OneToMany collection. There are vendor-specific extensions that do that but native JPA doesn’t cater for it.

    In part this is because JPA doesn’t actually know if it should delete something removed from the collection. In object modeling terms, this is the difference between composition and “aggregation*.

    In composition, the child entity has no existence without the parent. A classic example is between House and Room. Delete the House and the Rooms go too.

    Aggregation is a looser kind of association and is typified by Course and Student. Delete the Course and the Student still exists (probably in other Courses).

    So you need to either use vendor-specific extensions to force this behaviour (if available) or explicitly delete the child AND remove it from the parent’s collection.

    I’m aware of:

    • Hibernate: cascade delete_orphan. See 10.11. Transitive persistence; and
    • EclipseLink: calls this “private ownership”. See How to Use the @PrivateOwned Annotation.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple problem that I have not been able to find an
I have a simple problem that I've been stuck on for some time and
I have a simple problem that i cannot solve. I have a dictionary: aa
I have a simple problem. I want to delete all app request sent via
Very simple problem: I have a Public Sub (in a module) that I want
I have a simple problem. I created a custom UITableViewCell that includes a UISwitch
Probably a common problem, but anyway: Let's say I have a simple entity Task
I have a simple problem with admob here... I've tried all resources to add
i have very simple problem. I need to create model, that represent element of
I have a simple problem that reads an Excel file (using interop) and fills

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.