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

  • Home
  • SEARCH
  • 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 8657711
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:35:24+00:00 2026-06-12T15:35:24+00:00

i have a relation (one to many/ many to one) between parent and child

  • 0

i have a relation (one to many/ many to one) between parent and child in my code like this

The Parent

@JsonAutoDetect
@Entity
@Table(name = "Parent")
public class Parent{

    private Integer id;
    private List<Child> childs;

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column (name="idparent")
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL)
    @LazyCollection (LazyCollectionOption.FALSE)
    public List<Child> getChilds() {
        return childs;
    }
    public void setChilds(List<Child> childs) {
        for (Child child: childs) {
            child.setParent(this);
        }
        this.childs= childs;
    }
}

and the child

@JsonAutoDetect
@Entity
@Table(name="Child")
public class Child{

    private Integer id;
    private Parent parent;

    @Id
    @GeneratedValue(strategy= GenerationType.AUTO)
    @Column (name = "idchild")
    public Integer getId() {
        return id;
    }
    public void setId(Integer id) {
        this.id = id;
    }

    @ManyToOne(fetch = FetchType.EAGER)
    @NotFound(action = NotFoundAction.IGNORE)
    @JoinColumn(name = "idparent")
    @JsonIgnore
    public Parent getParent() {
        return parent;
    }
    public void setParent(Parent parent) {
        this.parent= parent;
    }
}

Everything is ok but when i do somthink like

parent.getChilds().remove(child);
session.update(parent);

the child is’nt removed from the table, what is the problem, can you help me please,
sorry for my bad english 🙁

  • 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-12T15:35:25+00:00Added an answer on June 12, 2026 at 3:35 pm

    child should not be removed from the database in this case. If that is the behavior you want, you need to enable “orphan removal”:

    @OneToMany(mappedBy = "parent", cascade = CascadeType.ALL, orphanRemoval=true)
    @LazyCollection (LazyCollectionOption.FALSE)
    public List<Child> getChilds() {
        return childs;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a one-to-many relation between Parent and Child table. In the parent object
I have the following one-to-many relation between two objects. Parent --> IList<Child> Now, I
I have multiple level parent-child tables(GrandParent, Parent and Child, all many to one relation,
i have an entity Entity1 that have one to many relation with Entity2 as
I use Entity Framework 4 and I have parent - child relation with Cascade
I have one to many relation between folders and docs tabels. I want to
I have an entity User and an entity Address. There is a relation One-to-Many
I am learning django admin, i have to models with a one-to-many relation between
I want to enable something like a one-to-many relation between a text object and
I have a question about Criteria method, one-to-many relation to the database, 'one' is

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.