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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T17:51:11+00:00 2026-05-29T17:51:11+00:00

I am currently trying to solve a problem, that I have using Hibernate 4

  • 0

I am currently trying to solve a problem, that I have using Hibernate 4 in a Java Swing application while having several many-to-many relationships between entities.

For example, the Project entity has a relationship with Person. Person and Project have a many to many relationship. A Project can be in many Categories, so there is a many-to-many relationship as well.

Person *-----* Project *-----* Category

When I have a swing form where I can edit all this information about a Person, a Project and a Category and it comes to saving the Person when the user hits the “save” button, what would be a possible solution to save/update Person?

void savePerson(Person p){
   Session sess = factory.openSession();
   Transaction tx = null;
   try {
       tx = sess.beginTransaction();

       // steps to be done

       tx.commit();
   }
   catch (RuntimeException e) {
       if (tx != null) tx.rollback();
   }
   finally {
       sess.close();
   }
}

Because there is also a collection of Projects inside Person and a collection of Categoy inside Project that might have been changed, do I have to do a recursive type of saving (first save/update all the sub-entities that the collections contain and then save/update the Person entity) or do I have to only save the Person entity and Hibernate applies the save/update mechanism to the whole entity-tree with Person as the root? Any best practices?

  • 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-29T17:51:12+00:00Added an answer on May 29, 2026 at 5:51 pm

    Have a look at CascadeType. You can set the behaviour for save/update operations directly by using the CascadeType in the relationship annotation:

    @OneToMany(cascade = CascadeType.ALL)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to solve a problem that, unfortunately, goes beyond my capacity. I have
I am currently trying to solve this problem in MySQL. I have MySQLdb installed.
I've got a rather tricky problem that I've been trying to solve for the
I am currently coding a HTML website into wordpress. The problem that i'm having
My problem is in trying to solve a Binary Integer Program through Java. I
I'm currently trying Backbone.js along with a rails app. My problem is, that I
I'm currently trying to solve a problem where I need to find the position
I am trying to solve one problem from Liang's book I have done most
I currently trying to find a solution, how to ensure that a test fails
I'm currently trying out db4o (the java version) and I pretty much like what

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.