1

Thanks for taking a look at this question in advance.

Basically, I have a few entities and here's the relationship.

Table A ---< Table AB >---- Table B

And the entity classes:

class A {    
     @ManyToMany
     @JoinTable(name = "A_B", joinColumns = { @JoinColumn(name = "A_ID",nullable = false) }, inverseJoinColumns = { @JoinColumn(name = "B_ID", nullable = false) })
     private List<B> bList;
 }

class B {    
    @ManyToMany(mappedBy = "bList")
    private List<A> aList;
}

Now I have 2 sessions accessing the same A object. I changed the bList value of A and saved it in session 1. So now, the object A in session 2 is stale and I saved an object C, which has reference of object A in its stale state.

I wonder why WITHOUT using cascade = {PERSIST, MERGE} by putting it into the @ManyToMany annotations, saving object C would also update the stale state of A back into the database, so the changes I made about object A in session 1 is gone?

Steven Beaupré
  • 21,343
  • 7
  • 57
  • 77
  • Did you ever find out how to solve this? I am having similar issues with "automatic" updates of a related table: http://stackoverflow.com/questions/31887328/prevent-unwanted-cascaded-table-updates – mvreijn Aug 08 '15 at 11:54

0 Answers0