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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T12:54:08+00:00 2026-06-14T12:54:08+00:00

I am working on import functionality where in i have to import data from

  • 0

I am working on import functionality where in i have to import data from a file and update it to the database using hibernate.

The object structure is : there is a parent and it has a Set of children.

When i do the import i first delete all the existing children and then add the new children i read from the file.

The way i do it is as below

parent = session.load(<id of parent>)  
parent.getchildrenSet.clear()  
parent.saveOrUpdate(parent);

Then, in a loop create new children and add it to the childrenSet on the parent. Then

parent.saveOrUpdate(parent);

Mappings are as below

In Parent

@OneToMany(cascade = CascadeType.ALL)
    @JoinTable(name = "CHILD_TABLE", joinColumns = { @JoinColumn(name = "CHILD_PARENT_ID") }, inverseJoinColumns = { @JoinColumn(name = "CHILD_ID") })
    @MapKeyColumn(name = "CHILD_ID")
    private Map<Long, Children> childrenMap;

In the Child

 @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "CHILD_PARENT_ID")
    private Parent parent;

When i run this code i expected the logs to print the DMLs in the below order
1. Delete all the children
2. Insert new children
3. Update the parent

But what it prints is
1. Insert new children
2. Update the parent
3. Delete all the children

So, as a result of the above order, it removes all the children from the parent, even the ones which i added newly because of import.

It seems like hibernate doesnt maintain the order in which i had called the DMLs. Can anyone provide me some suggestions on this? Let me know if the question is not clear.

  • 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-14T12:54:10+00:00Added an answer on June 14, 2026 at 12:54 pm

    Collections.clear() doesn’t equate to delete. You need to call an explicit delete to ensure you delete before you insert. Else, the implicit delete will get exexuted when your session terminates.

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

Sidebar

Related Questions

I have a Graphics object of JPanel and that is working fine: import java.awt.Color;
I'm working on an import from a CSV file to my ASP.NET MVC3/C#/Entity Framework
I'm working with Spring/Hibernate (using NetBeans 6.9.1). I need to import Excel sheet into
In my app I have been working to import and export the database. I
i am working on one music app where we can import music from iPod
I'm working on an IMAP client using Ruby and Rails. I can successfully import
I have been working on and testing the jQuery autcomplete functionality here on my
I've recently started using the Areas functionality of the Preview2 and it was working
For a project I'm working on, i'm adding import/export functionality. This is working OK,
I'm working on a Google Chrome extension that provides import/export functionality and I ran

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.