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

@Labels setter is not called when loading entity #414

Closed
jdorleans opened this issue Sep 29, 2017 · 6 comments
Closed

@Labels setter is not called when loading entity #414

jdorleans opened this issue Sep 29, 2017 · 6 comments
Labels

Comments

@jdorleans
Copy link
Contributor

Expected Behavior

Whenever loading an entity, OGM should call (or at least have the option to) @Labels setter property.

Current Behavior

This seems to be a regression and @Labels setter is not called anymore.

Possible Solution

IDK

Steps to Reproduce (for bugs)

Please, check a simple example I've created on my fork: jdorleans@7db1454

Context

In many cases I wanna represent transient fields in my domain as Labels. For that I need to:

  1. update labels whenever the transient field changes
  2. update the transient field back to its state when the labels are loaded from the DB

However, it seems the current version of OGM does not call setter for labels anymore. As a result, all transient fields of my domain are no longer updated.

Your Environment

  • OGM Version used: 3.0.0
  • Java Version used: 1.8
  • Neo4J Version used: 3.2
  • Bolt Driver Version used (if applicable):
  • Operating System and Version: Ubuntu and Mac
  • Link to your project: jdorleans@7db1454
@nmervaillie
Copy link
Member

There are a couple a changes when migrating from OGM 2.1 to 3.0. One of them is that getters/setters access is not supported anymore.

The docs are not published yet, but should very soon. In the meantime, you can check the migration guide here.

Can you have a look give some feedback please ? Maybe it is something we should improve in the docs.

From what I see in your example, you might be interested in the @PostLoad annotation, which you can use in you entities to do some custom initialization after loading.

@jdorleans
Copy link
Contributor Author

Thx @nmervaillie I'll check and give some feedback.

@jdorleans
Copy link
Contributor Author

@PostLoad solves it, but I'm forced to use the annotation at the lowest level. I'd like to have a postLoad() method in my Entity abstraction and just override it whenever needed by its children.

It seems MethodsInfo only runs on declared methods instead of all the hierarchy methods.
Probably that could solve the problem when looking for the annotation. So, instead of calling: cls.getDeclaredMethods() it'd call cls.getMethods(). Not sure if we should create another issue for that.

@frant-hartm
Copy link
Contributor

Ok, that seems like a bug.

@jdorleans
Copy link
Contributor Author

I can confirm it's definitely a bug. I hope the tests I included in my new PR (#484) will help solve this. Please, check on this test: https://github.com/neo4j/neo4j-ogm/pull/484/files#diff-8af1ea6d5cb8f598b436005e95aeba80R83

jdorleans added a commit to jdorleans/neo4j-ogm that referenced this issue May 12, 2018
- Loading parent methods and replacing child's overridden ones
- Adding test for overridden @PostLoad method

NOTE:
- Reflection method invocation calls overridden methods if exists
- Those changes depends on neo4j#484

neo4j#414
@michael-simons
Copy link
Collaborator

I'm closing this issue in favor of #516. We don't support setter-semantics anymore and the bug regarding @PostLoad should be tracked separate. Thanks.

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

No branches or pull requests

4 participants