Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot update labels if entity using @Id is loaded in a different session #488

Closed
jdorleans opened this issue May 13, 2018 · 1 comment
Closed

Comments

@jdorleans
Copy link
Contributor

jdorleans commented May 13, 2018

It is not possible to update labels if we load an entity in a new session. This does not happen when using graph id, but in cases when entity has another primary id using annotation @Id.

When using a different primary ID such as @Id in a new variable, the mapping context and identity map are not maintained in sync with entities ids as such label history does not track changes correctly and uses wrong ids on the session.

To reproduce, first be sure you have an entity using @Id such as an uuid, then:

  1. Save the entity with labels
  2. Load the same entity using a new session: sessionFactory.openSession()
  3. Save the loaded entity with new labels
  4. Load the entity once more and check the new labels - FAIL!
    New labels will not be saved, instead, the old ones are maintained.

Possible Solution

To fix the mapping context and identity updates when registering nodes and relationship into session.
I'm providing a PR for this #489. Also, I believe this issue is somewhat connect to #237.

Your Environment

  • OGM Version used: 3.1.0
jdorleans added a commit to jdorleans/neo4j-ogm that referenced this issue May 13, 2018
- Merging primaryId mapping for both nodes and relationship
- Remembering identity with existing ID without calling nativeId method
- Reusing identity update logic for both nodes and relationships
- Creating tests in EntityAbstractionTest and PizzaIntegrationTest
- Testing label updates with graphId and different primaryId using @id

neo4j#488
michael-simons added a commit that referenced this issue Nov 30, 2018
The label history got stored under a generated, negative id when an entity
without native id field got loaded into the session.

It could have been fixed by either changing the order of when things got "remembered"
and when the id cache got filled or as we did it now, by using the native node id
which cannot be null at the time of remembering a node.

Tests have been contributed by Jonathan D'Orleans.

Co-authored-by: Jonathan D'Orleans <jonathan.dorleans@gmail.com>
michael-simons added a commit that referenced this issue Nov 30, 2018
The label history got stored under a generated, negative id when an entity
without native id field got loaded into the session.

It could have been fixed by either changing the order of when things got "remembered"
and when the id cache got filled or as we did it now, by using the native node id
which cannot be null at the time of remembering a node.

Tests have been contributed by Jonathan D'Orleans.

Co-authored-by: Jonathan D'Orleans <jonathan.dorleans@gmail.com>
@michael-simons
Copy link
Collaborator

Fixed with 95b7cb0 in master and also in 3.1.x.

Thanks for reporting this and also for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants