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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:13:36+00:00 2026-05-19T17:13:36+00:00

NOTE: I am using a J2EE Spring MVC + Hibernate with both using annotations

  • 0

NOTE: I am using a J2EE Spring MVC + Hibernate with both using annotations for this.

I have a file system modeled in hibernate with a hierarchy of folders and files in these folders. The folders each refers to their parent folder or null if they are a root folder. They do not have references to their children since there is a bit of polymorphism there and I decided it would be best to query to retrieve children. Regardless, that combined with the fact that I have a requirement to use MySQL triggers to track history in the database, means that Cascading delete is not an option.

As a result I have to delete things manually. Now, the recursive logic for this seems fairly straight forward, all I should have to do is the following in the folder DAO:

// Pseudo-java-code
deleteFolder(Folder folder)
{
  Set<Folder> folders = getFoldersInFolder(folder);
  for (Folder child:folders) {
    deleteFolder(child);
  }
  Set<File> files = fileDAO.getFilesInFolder(folder);
  for (File f:files) {
     fileDAO.deleteFile(f);
  }
  remove(folder); // method from org.execution.dao.JpaDao
}

Unfortunately I keep getting the “deleted instance passed to merge” exception when it attempts to commit the changes in the transaction. The DAO is being called by a service which has the following transactional annotation placed at the top of the class:

@Transactional(isolation = Isolation.DEFAULT, propagation = Propagation.REQUIRED)

How do I fix this?

  • 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-19T17:13:37+00:00Added an answer on May 19, 2026 at 5:13 pm

    I feel kind of silly now that I know the answer. I was calling “remove(folder);” after my call to the recursive function, meaning that the code attempted to remove the folder twice.

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

Sidebar

Related Questions

Note: Using MySQL 4.0, which means no subqueries (at present). I have 2 tables:
(NOTE: This question is not about escaping queries, it's about escaping results) I'm using
I am using Spring 3.0. Can i read a property file from a localdrive
NOTE: Using .NET 2.0, and VS2005 as IDE Hello all, I'm working on logging
Note: Using raw Win32 CreateTheard() API No MFC An interface is simply a pointer
Note : No MFC No ATL Using Visual C++ While attempting a connection between
NOTE: I am not set on using VI, it is just the first thing
Note: while the use-case described is about using submodules within a project, the same
Note: This was posted when I was starting out C#. With 2014 knowledge, I
Note: Originally this question was asked for PostgreSQL, however, the answer applies to almost

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.