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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:44:47+00:00 2026-05-30T10:44:47+00:00

I have created a many to many mapping in spring roo between two entities

  • 0

I have created a many to many mapping in spring roo between two entities Person and car and as expected I see a new table Person_Car. Below is the code in Person.java

@ManyToMany(cascade = CascadeType.ALL, mappedBy = "persons")
private Set<Car> cars= new HashSet<Car>();

Now I want to add entries in the table. I set the cars to the person object and do person.merge().

@RequestMapping(value ="/saveCars", method = RequestMethod.POST)
@ResponseBody
public String saveCars(@RequestParam("personId")Long personId,                                      @RequestParam("cars") String incomingCars){
Map<String, Object> response = new HashMap<String, Object>();
try{        
...   
Person person = Person.findPerson(personId);  
Set<Car> cars = person.getCars();
        for(int i=0 ; i<temp.length ; i++){
            carID = Long.parseLong(temp[i]);
            cars.add(Car.findCar(carID));
        }
        person.setCars(cars);
        person.merge();
    }
    LOG.debug("cars successfully added to questionnaire");
    response.put("message", "success");
} 
return new JSONSerializer().exclude("*.class").deepSerialize(response);
}

However, no entries are being made in the Person_Car table. But, when I do something like

Person person = Person.findPerson(personId);
person.setName("Jonathan");
person.merge();

I see the change reflected in the person table. What am I doing wrong? Thanks

  • 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-30T10:44:49+00:00Added an answer on May 30, 2026 at 10:44 am

    Try to add @Transactional(rollback=false) to your controller method.

    rollback=false is default so you can skip it, and only @Transactional is left.

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

Sidebar

Related Questions

I am trying to generate a unidirectional one-to-many mapping between two JPA entities. In
I have entities Post and Tag , where there is a many-to-many relationship between
I have problem with one-to-many mapping. Two tables questions(PK(id), text) and answers(PK(id, questionId), text)
I want to create Many-One Mapping between two tabels, Expense(ID, NAME, CATEGORY) and Category(ID,
Im using c# .net windows application form. I have created many databases with many
I have created Twitter bots for many geographic locations. I want to allow users
I have created a fairly substantial Java GUI application with many form windows where
Many programs have created a huge amount of swap files. They annoy me, because
I have created a great stand-alone web form in asp.net utilizing many jQuery features
Here is my problem. I have created a pretty heavy readonly class making many

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.