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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:44:38+00:00 2026-05-27T06:44:38+00:00

I have a problem that’s equal to the one presented here: how to define

  • 0

I have a problem that’s equal to the one presented here: how to define an inverse cascade delete on a many-to-one mapping in hibernate

After searching for a while I can’t find a decent/clean solution for this. I can’t have the parent entity have an @OneToMany to the child, because they are at different modules. I wanted to try the EntityListener that would delete the children before the parent is, but I can’t because, again, they are at different modules.

Does anyone know a clean solution to this? I am thinking about to use AspectJ to listen to the call of the delete method from the ParentDao, but this is not a clean solution and I will have to implement one for each entity that have this kind of relation to the Parent class.

This kind of cascade seems to be a basic feature and I am kind dissapointed in seeing that hibernate does not support it :/

  • 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-27T06:44:39+00:00Added an answer on May 27, 2026 at 6:44 am

    Based on JB Nizet answer I changed my DAO to have a DeleteOperationListener (My base DAO implementation is based on “Don’t Repeat the DAO”[1].) In this way I have a generic solution in case I find myself in the same situation again. The structure looks like this:

    public interface GenericDao<T, PK extends Serializable> {
        // CRUD methods
    
        // delete operation listeners.
        void addDeleteListener(DeleteOperationListener<T, PK> deleteOperationListener);
    
        public interface DeleteOperationListener<T> {
            void preDelete(T entity);
            void posDelete(T entity);
        }
    }
    

    And my abstract hibernate implementation I can notify the observers about the delete.

    @Override
    public void delete(T entityToDelete) {
        notifyPreDelete(entityToDelete);
        this.getHibernateTemplate().delete(entityToDelete);
        notifyPosDelete(entityToDelete);
    }
    

    And now I have a different class that handles the deletion of the children without needing to change the DAOs:

    @Service
    public class ParentModificationListener
        implements GenericDao.DeleteOperationListener<Parent> {
    
        private ChildDao childDao;
    
        @Autowired
        public ParentModificationListener(ChildDao childDao, ParentDao parentDao) {
            this.childDao = childDao;
            parentDao.addDeleteListener(this);
        }
    
        @Override
        public void preDelete(Parent parent) {
            this.childDao.deleteChildrenFromParent(parent);
        }
    
        @Override
        public void posDelete(Parent parent) {
            // DO NOTHING
        }
    }
    

    [1] http://www.ibm.com/developerworks/java/library/j-genericdao.html

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

Sidebar

Related Questions

I have a problem that I have found many similar problems related to multi
I have the problem that a given object could be one of several different
I have this problem that i have code like this in many of my
i have this problem that i can't solve for days now...here is my code.
I have a problem that is surely familiar to many: I'm making a call
In a couple of scripts that I use I have problem that is intermittent.
I have a problem that confuses my users, being that although an item is
I have the problem that an specific step in Ant can only be executed
I have a problem that I would like have solved via a SQL query.
I have a problem that I feel is best implimented in a stand alone

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.