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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:21:56+00:00 2026-05-25T13:21:56+00:00

Assume entity classes Foo and Bar like: class Foo { @ManyToMany @JoinTable(name = FooBar,

  • 0

Assume entity classes Foo and Bar like:

class Foo {

    @ManyToMany
    @JoinTable(name = "FooBar",
        joinColumns = @JoinColumn(name = "foo"),
        inverseJoinColumns = @JoinColumn(name = "bar"))
    public List<Bar> getBars() {
        return bars;
    }

}

class Bar {
    // ...
}

When I save a Foo entity, I want to save bars list also, but only the mapping list, for example:

Bar oldBar = foo.getBars().get(0);
oldBar.setSomething("new-value"); // Change to the entity.

Bar newbar = new Bar();
foo.getBars().add(newbar);  // Change to the list.

saveOrUpdate(foo);

I want saveOrUpdate persist the changes to the list, but not changes to the entity. Can I?

  • 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-25T13:21:56+00:00Added an answer on May 25, 2026 at 1:21 pm

    CascadeType.PERSIST sort of does what you want, but it depends on the starting state of your foo object. If the old foo is in the managed state, then changes you make to oldBar are persistent. That can’t really be ‘turned off.’ Why would you change a value on a persistent object if it’s not supposed to get changed? It doesn’t really make sense in an ORM context.

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

Sidebar

Related Questions

Assume I have the following two classes: public class User : Entity { public
Assume the following entity classes: public class Player { public virtual int ID {
Assume that we have two classes public class EntityA { public EntityB EntityB {
Assume there are two entities with ManyToOne relation: @Entity public class A { private
Given these base classes and interfaces public abstract class Statistic : Entity, IStatistic {
Assume the following class: public class MyEnum: IEnumerator { private List<SomeObject> _myList = new
Assume I have a class foo, and wish to use a std::map to store
Assume I have a such model: class Entity(models.Model): start_time = models.DateTimeField() I want to
Assume we have a method like this: public IEnumerable<T> FirstMethod() { var entities =
Assume I have these simplified EF generated entities... public class PurchaseOrder { public int

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.