Skip to content

Renamed properties are not included during writes and not projected during reads. #2371

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

Closed
meistermeier opened this issue Aug 31, 2021 · 3 comments
Assignees

Comments

@meistermeier
Copy link
Collaborator

Inspired by https://stackoverflow.com/questions/68938823/sdn6-projection-interfaces-with-property-mapping
we should at least check if it is possible to create a connection between the defined method in a projection to the field in the domain object.

Reproducer / play along project: https://github.com/meistermeier/neo4j-issues-examples/tree/master/so-68938823

@meistermeier meistermeier self-assigned this Sep 2, 2021
meistermeier added a commit that referenced this issue Sep 2, 2021
meistermeier added a commit that referenced this issue Sep 2, 2021
@meistermeier
Copy link
Collaborator Author

First analysis (unfortunately no solution yet):
The problem roots in the current situation that we provide a list of parameters to the modifying query that is based on the metadata of the domain. At this moment there are only graph property names left. Filtering them with the java properties list does not work.

  1. We could add the graph property names to the property filter constructs when starting the operation. But this won't work out of the box because the projection field detection is based on PropertyPaths. Adding the graph property names here would lead into an exception because those are invalid PropertyPaths.

  2. There is the moment of creating PropertyFilter out of the provided PropertyPaths. At this point the MappingContext is missing to e.g. call getPersistentPropertyPath to get the property information needed. I personally would try to avoid throwing a MappingContext in there.

  3. This is option has a broader impact: We should consider filtering the properties before invoking the binder function for write. Or pass the filter on to the function. This would avoid unnecessary conversion upfront. In 1 and 2 we create sets that filter the parameters list after the list got created.

I would like to investigate option 2 with an external "alternative property name provider" approach.

@meistermeier
Copy link
Collaborator Author

It seems that option 2 is a valid one and does not too much influence the existing code base or make it unnecessary complex.

@michael-simons michael-simons changed the title Respect @Property information in projection. Renamed properties are not included during writes and not projected during reads. Feb 1, 2022
michael-simons added a commit that referenced this issue Feb 1, 2022
Domain attributes can be renamed using the `@Property` annotation when
being mapped to and read from graph properties. That renaming must also
happening when using projections. As with #2451 in
582fd7d this is kind of a problem with
the existing filter mechanism that works after the stack has dealt with
the actual properties.

After all properties and paths are computed, they will be translated as
late as possible before checked for inclusions:

- When writing just before it is checked whether to add them to the
  properties parameter or not
- When reading after they have been map-projected from the database into
  the result set but before they are checked for inclusions.

Also addressed here is the a workaround for writes: In case a user had
an interface based projection and used the graph property name as
accessor, a write would succeed, however a read would fail. A property
accessor has now been registered with the default projection factory
that translates a failure to access an entity property (attribute) once.

This fixes #2371.
@michael-simons
Copy link
Collaborator

I agree with option 1+2: Throwing in the renamed attributes at the moment when the dotPaths are created in 2 when we the entity is still available works. But it needed to be done in both reads and writes. I wanted to avoid another concept like the alternative naming function. We have too many call sites that are affect (6, actually, 3 for imperative and 3 for reactive).

Also I took care of keeping the workaround in the SO question working (actually made it work for reads, too).

michael-simons added a commit that referenced this issue Feb 1, 2022
Domain attributes can be renamed using the `@Property` annotation when
being mapped to and read from graph properties. That renaming must also
happening when using projections. As with #2451 in
582fd7d this is kind of a problem with
the existing filter mechanism that works after the stack has dealt with
the actual properties.

After all properties and paths are computed, they will be translated as
late as possible before checked for inclusions:

- When writing just before it is checked whether to add them to the
  properties parameter or not
- When reading after they have been map-projected from the database into
  the result set but before they are checked for inclusions.

Also addressed here is the a workaround for writes: In case a user had
an interface based projection and used the graph property name as
accessor, a write would succeed, however a read would fail. A property
accessor has now been registered with the default projection factory
that translates a failure to access an entity property (attribute) once.

This fixes #2371.
michael-simons added a commit that referenced this issue Feb 1, 2022
Domain attributes can be renamed using the `@Property` annotation when
being mapped to and read from graph properties. That renaming must also
happening when using projections. As with #2451 in
582fd7d this is kind of a problem with
the existing filter mechanism that works after the stack has dealt with
the actual properties.

After all properties and paths are computed, they will be translated as
late as possible before checked for inclusions:

- When writing just before it is checked whether to add them to the
  properties parameter or not
- When reading after they have been map-projected from the database into
  the result set but before they are checked for inclusions.

Also addressed here is the a workaround for writes: In case a user had
an interface based projection and used the graph property name as
accessor, a write would succeed, however a read would fail. A property
accessor has now been registered with the default projection factory
that translates a failure to access an entity property (attribute) once.

This fixes #2371.

# Conflicts:
#	src/test/java/org/springframework/data/neo4j/integration/reactive/ReactiveProjectionIT.java
@michael-simons michael-simons mentioned this issue Jan 4, 2023
4 tasks
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