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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T02:17:51+00:00 2026-05-28T02:17:51+00:00

I have a parent child relationship between 2 classes Parent @Entity @Table(name = PARENT)

  • 0

I have a parent child relationship between 2 classes

Parent

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

    @Id
    @GeneratedValue
    @Column(name = "ID")
    private Long id;


    @Column(name = "NAME")
    private String name;

    @Column(name = "WAGES")
    private BigDecimal wages;


    @OneToMany(cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.LAZY)
    @JoinColumn(name = "PARENT_ID")
    private List<Child> children;   

    // getters and setters

    }

Child

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

    @Id
    @GeneratedValue
    @Column(name = "ID")
    private Long id;

    @Column(name = "NAME", nullable = false)
    private String name;

    @Column(name = "PARENT_ID", nullable = false, insertable = false, updatable = false)
    private Long parentId;

    // getters and setters
}

In this particular case, there are no child records for the parent. When I update the parent , hibernate throws the following exception even though the parent does not contain any child records and I am not trying to update/add/remove any child records. The children collection is not accesses at all in code. I am using all JPA annotations. Hibernate version is 3.6.7.Final. Any pointers is appreciated.

org.hibernate.HibernateException: A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance:com.mycode.Child

//Service code

public Parent update(ParentDto dto) {
        Parent parent = parentDao.findById(dto.getId());    
        // Using Dozer to map dto object to entity object
        // http://dozer.sourceforge.net/
        dozerMapper.map(dto, parent);       
        taxFormW2Dao.saveOrUpdate(parent);
        return Parent;
    }

// Dao code

public void saveOrUpdate(Parent parent){
        // HibernateTempplate is injected through Spring
        HibernateTemplate template = getHibernateTemplate();
        getHibernateTemplate().saveOrUpdate(parent);    
    }
  • 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-28T02:17:51+00:00Added an answer on May 28, 2026 at 2:17 am

    I suspect the dozerMapper does something with the collection. Try copying the fields from the DTO to the entity without using dozer.

    Moreover, saveOrUpdate takes a detached instance, and attaches it to the session. It throws an exception if the attached version of the detached entity is already loaded in the session.

    The parent passed to saveOrUpdate is already attached, and the call to saveOrUpdate is thus completely unnecessary (and could cause an exception). Changes made to an attached entity are automatically persisted by Hibernate. You don’t need to call saveOrUpdate, update or merge.

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

Sidebar

Related Questions

I have a table which defines a child-parent relationship between nodes: CREATE TABLE node
I have a relationship between two base classes: public abstract class RecruiterBase<T> { //
I have a bi-directional one-to-many relationship defined between Parent and Child classes. I'm looking
I have a parent/child database relationship between the table ACCOUNT and the table USER.
I have db table with parent child relationship as: NodeId NodeName ParentId ------------------------------ 1
I have a parent-child relationship between two objects. Parent :has_many :children Child :belongs_to :parent
I'm using Entity Framework 4 and have a one-to-many relationship between a parent and
I have a one to many entity relationship between two entities: EntityP (Parent) <-->>
I'm using the Entity Framework to model a simple parent child relationship between a
I have a parent-child relationship between Teacher and StudentReport . Each StudentReport has a

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.