Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » Shared Cache produce invalid 1-N elements that are not managed by entity manager
Shared Cache produce invalid 1-N elements that are not managed by entity manager [message #1783172] Thu, 08 March 2018 19:51 Go to next message
Alexander Roytman is currently offline Alexander RoytmanFriend
Messages: 4
Registered: March 2018
Junior Member
I have a 1-N (mappedBy) List with @OrderColumn specified
With default cache settings (shared) I see that a collection element obtained from the collection is actually does not belong to the entity manager of collection's owning entity entityManager.contains() returns false and any operations such as remove on the entity fail with "non-managed" entity error

The steps are

1. obtain an entity manager (EM) create parent and child entities and commit
2. obtain a new EM and get first element from the child collection
3. test using entityManager.contains() - false, or try EM.remove() and commit fails
3a. Alternatively after #2 obtain that child element directly from EM - it returns instance different (checked with System.identityHash()) from the one obtained from collection in #2 that one is managed by the EM and can be deleted fine
Also element I get from owner collection appears to be the same instance in multiple EM I obtain telling me it is probably returns shared instance instead of EM specific clone

turning caching off solves the problem and everything performs as expected

I would greatly appreciate your suggestions
Re: Shared Cache produce invalid 1-N elements that are not managed by entity manager [message #1783182 is a reply to message #1783172] Thu, 08 March 2018 21:28 Go to previous messageGo to next message
Alexander Roytman is currently offline Alexander RoytmanFriend
Messages: 4
Registered: March 2018
Junior Member
I am using version 2.7.1
There is one wrinkle. Collection of elements I mentioned above is not accessed directly via a getter but is wrapped in an inner class which is then returned.

  @OneToMany(mappedBy = "docket", cascade = CascadeType.ALL, orphanRemoval = true)
  @OrderColumn(name = "SORT_ORDER")
  private List<Milestone> milestones = new ArrayList<Milestone>();
  
  private transient @Transient DelegatingList<Milestone> _ro_milestones;

  public List<Milestone> getMilestones() {
    if (_ro_milestones == null) {
      _ro_milestones = new DelegatingList<Milestone>() {
        @Override public List<Milestone> getSubject() {
          return milestones;
        }
      };
    }
    return _ro_milestones;
  }


and the thing is it seems that _ro_milestones is get cloned from shared into EM instance regardless of being marked as transient or @Transient. I thought it is because of @CopyPolicy being "clone" but with my class annotated with @InstantiationCopyPolicy or internal weaving set to false or even with weaving turned off all together it is still happening - _ro_milestones filed is copied over to and from shared instance and thus holds references to owning instance in the very first EM that populated shared cache.

How do I make eclipselink NOT to copy transient field to/from shared cache?
Re: Shared Cache produce invalid 1-N elements that are not managed by entity manager [message #1783604 is a reply to message #1783182] Wed, 14 March 2018 14:43 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1300
Registered: July 2009
Senior Member
You have set a number of advanced options, and it isn't clear what your model is exactly. EclipseLink as far as I've seen does not touch fields marked as @Transient, so you'll have to show more of your model to find out what is going on. Maybe make a small test case that reproduces the issue so you can narrow down the settings involved. If it is private, how is the _ro_milestones collection getting set - make sure you don't have other accessors that might cause it to get set from JPA accessed method or during the clone process.
Re: Shared Cache produce invalid 1-N elements that are not managed by entity manager [message #1783639 is a reply to message #1783604] Wed, 14 March 2018 19:30 Go to previous message
Alexander Roytman is currently offline Alexander RoytmanFriend
Messages: 4
Registered: March 2018
Junior Member
I got everything working with @InstantiationCopyPolicy on all classes (mixing default policy with @InstantiationCopyPolicy) actually is causing erratic behavior of eclipselink. What I am saying is that Eclipselink should allow to turn of copying of transient fields in its default policy globally. Copying transient fields managed by the application and not by persistence layer to shared cache and then from it to entity manager instances is asking for trouble. like the one I explained above
Previous Topic:Cant prevent transient fields from being copied from shared cache to entity manager instances
Next Topic:Attribute Converter not working properly on lists
Goto Forum:
  


Current Time: Sun Jun 24 03:48:18 GMT 2018

Powered by FUDForum. Page generated in 0.02267 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top