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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:37:24+00:00 2026-05-16T06:37:24+00:00

I have some problem with delation of associations, this is my code : Classe

  • 0

I have some problem with delation of associations, this is my code :

Classe ModuleVersion

@ManyToMany(mappedBy="listModuleVersions")
private List<SuiteVersion> suiteVersions = new ArrayList<SuiteVersion>();

Classe SuiteVersion

@ManyToMany()
private List<ModuleVersion> listModuleVersions = new ArrayList<ModuleVersion>();*

I would like to be able to delete automatically a suiteVersion or a moduleVersion with deletion of association. For example, if i delete a SuiteVersion with this code is delete automatically the association SuiteVersion to ModuleVersion. But if i delete a moduleVersion it doesn’t automatically delete the association of SuiteVersion -> ModuleVersion. It is possible to do this automatically with ModuleVersion ?

Update

This is the action perform by hibernate if i delete a module with the adding of CASCADETYPE.REMOVE …

Hibernate: delete from SUITE_VERSION_MODULE_VERSION where suiteVersions_ID_SUITE_VERSION=?
Hibernate: delete from SUITE_VERSION_MODULE_VERSION where suiteVersions_ID_SUITE_VERSION=?
Hibernate: delete from SUITE_VERSION_MODULE_VERSION where suiteVersions_ID_SUITE_VERSION=?
Hibernate: delete from SUITE_VERSION_MODULE_VERSION where suiteVersions_ID_SUITE_VERSION=?
Hibernate: delete from SUITE_VERSION_MODULE_VERSION where suiteVersions_ID_SUITE_VERSION=?
//Hibernate: delete from SUITE_VERSION where ID_SUITE_VERSION=?
//Hibernate: delete from SUITE_VERSION where ID_SUITE_VERSION=?
Hibernate: delete from MODULE_VERSION where ID_MODULE_VERSION=?
//Hibernate: delete from SUITE_VERSION where ID_SUITE_VERSION=?
//Hibernate: delete from SUITE_VERSION where ID_SUITE_VERSION=?
Hibernate: delete from MODULE_VERSION where ID_MODULE_VERSION=?
//Hibernate: delete from SUITE_VERSION where ID_SUITE_VERSION=?
Hibernate: delete from MODULE_VERSION where ID_MODULE_VERSION=?
Hibernate: delete from MODULE where ID_MODULE=?

I just want the part none comitted to be executed.
Thank you in advance for your help,

Update2

I tried to delete the module with this method implementation :

    public static void removeModule(Module module) {
    for(ModuleVersion moduleVersion : module.getListModuleVersion()){
        for(SuiteVersion suiteVersion : moduleVersion.getSuiteVersions()){
            sessionFactory = HibernateFactory.getSessionFactory();
            session = sessionFactory.getCurrentSession();
            transaction = session.beginTransaction();
            suiteVersion.removeFromModuleVersions(moduleVersion);
            transaction.commit();
        }
    }
    sessionFactory = HibernateFactory.getSessionFactory();
    session = sessionFactory.getCurrentSession();
    session.delete(module);
    transaction.commit();
}

But i have this problem now :

Exception in thread "AWT-EventQueue-0" java.util.ConcurrentModificationException

Best regards,

Florent.

P.S: I’m french, sorry for my 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-05-16T06:37:25+00:00Added an answer on May 16, 2026 at 6:37 am

    Thank you for you answer. But if i had this. the suiteVersion is also deleted. I just want the row in the table of associations suiteVersion -> moduleVersion be deleted.

    I think I got it now: you want to break an association and to get the corresponding record removed from the join table. That’s not what I understood from the original question. Anyway…

    To do so, well, you have to do what I wrote, to break the association, i.e. to remove the corresponding entities from their respective association collection (you have to update both sides of the link too since it’s a bidirectional association). Something like this:

    session.getTransaction().begin();
    SuiteVersion suite = ... // retrieved in some way
    ModuleVersion module = ... // retrieved in some way
    suite.getModuleVersions().remove(module);
    module.getSuiteVersions().remove(suite);
    session.getTransaction().commit(); // the "association" record should get removed
    

    But I suggest using helper methods:

    @Entity
    public class SuiteVersion {
        ...
        @ManyToMany
        private List<ModuleVersion> moduleVersions = new ArrayList<ModuleVersion>();
    
        ...
    
        public void removeFromModuleVersions(ModuleVersion module) {
            this.moduleVersions.remove(module);
            module.getSuiteVersions().remove(this);
        }
    
        public void addToModuleVersions(ModuleVersion module) {
            this.moduleVersions.add(module);
            module.getSuiteVersions().add(this);
        }
    
    }
    

    And then your code becomes:

    session.getTransaction().begin();
    SuiteVersion suite = ... // retrieved in some way
    ModuleVersion module = ... // retrieved in some way
    suite.removeFromModuleVersions(module);
    session.getTransaction().commit();
    

    See also

    • 1.2.6. Working bi-directional links

    Update: Your “new” problem is a pure Java related problem: you can’t modify a collection while iterating on it, at least not with your current approach. You need to use an Iterator and Iterator#remove().

    Related questions

    • Java: Efficient Equivalent to Removing while Iterating a Collection
    • Java: How to remove elements from a list while iterating over/adding to it
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some problem with this code. Notice the comments. Why that? struct node
I have some problem with this code, when I click the start button everything
I have some problem with my code public IQueryable<PageItems> GetPageById(Guid Id) { var xml
I have some problem to order an array by a field of this, here
I have some problem with my cfml website. I have used the below code
i am new in JSP,i have some problem with the following code : <%@
I have some problem with these code snippets: CSS: #wrapper{ width: 600px; background: gray;
I have some problem converting a MYSQL query to CI syntax. This my MySQL
I have some problem with replace command. Input file i have this {a[$1]=a[$1]FS$2}END{for(i in
I have some problem with Jquery Autocomplete plugin ( http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ ) I got it

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.