Skip to content

@Relation annotation not considered for link relation defaults #1974

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
dlynch158 opened this issue Sep 24, 2020 · 6 comments
Closed

@Relation annotation not considered for link relation defaults #1974

dlynch158 opened this issue Sep 24, 2020 · 6 comments
Assignees

Comments

@dlynch158
Copy link

Hello,

The JSON that gets returned is this:

{
    "_embedded": {
        "employees": [

I am attempting to change an entity name from employees to "workers" by using the following Relation annotation:

@Entity
@Relation(collectionRelation = "workers", itemRelation = "worker")
public class Employee {

This has no effect on what gets returned.

The full source code of my test case is at:

https://github.com/dlynch158/relationtest

Thank you.

@mschout
Copy link

mschout commented Oct 12, 2020

I'm seeing the same issue, running under spring-boot-start-parent 2.3.4.RELEASE. Adding @Relation to the model class seems to have no effect on the _embedded name.

@laobuda
Copy link

laobuda commented Dec 4, 2020

we are encountering the same problem after migrating to spring-boot-start-parent 2.3.6.RELEASE.

@odrotbohm
Copy link
Member

The linked project actually builds fine using ./gradlew test. Anything I am missing?

@odrotbohm
Copy link
Member

Nevermind, I made my way through it. There are a couple of things that are problematic / wring with the project but ultimately also a challenge I'd like to get you folks' input on:

The project pulls in Spring Data REST. I.e. the requests are not answered by the code contained in the project but Spring Data REST. That in turn uses repository metadata and defaults to determine the link relations. Those are not customized and thus the defaults derived from the repository apply. More on that below. If I remove Spring Data REST, annotate the controller and representation model assembler properly, the link relations are customized as expected.

With Spring Data REST in play, we currently order the repository based metadata inspection to trump the one base on entities. Otherwise @RepositoryRestResouce would be largely without effect. It appears that the lookup of the mapping metadata of Spring Data REST currently does not consider @Relation. We're running into a chicken and egg problem here as the SD REST LinkRelationProvider implementation would need access to all other LinkRelationProvider implementations but itself and the delegating wrapper instance to delegate to those to properly consider the overall arrangement.

Long story short, I am inclined to move this over to Spring Data REST as it clearly needs to be fixed there. The workaround in the meantime is to use @RepositoryRestResource on the repository to define alternate link relations if you use Spring Data REST.

@odrotbohm odrotbohm transferred this issue from spring-projects/spring-hateoas Feb 17, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Feb 17, 2021
@odrotbohm
Copy link
Member

Looks like this a rather trivial fix as the metadata detection already uses the LinkRelationProvider coming from RepositoryRestConfiguration, which is currently set up to only use the one based on the Evo Inflector library. Tweaking that to a DelegatingLinkRelationProvider with the one considering @Relation first is rather easy. That's also a good way of getting the annotation to work with the current state of affairs: just configure an LRP as just described via RepositoryRestConfiguration.setRelProvider(…).

@odrotbohm odrotbohm removed the status: waiting-for-triage An issue we've not yet triaged label Feb 17, 2021
@odrotbohm odrotbohm self-assigned this Feb 17, 2021
@odrotbohm odrotbohm added this to the 3.5 M3 (2021.0.0) milestone Feb 17, 2021
@odrotbohm odrotbohm changed the title @Relation Annotation does not change entity name @Relation annotation not considered for link relation defaults Feb 17, 2021
odrotbohm added a commit that referenced this issue Feb 18, 2021
…relation.

RepositoryRestConfiguration now defaults the LinkRelationProvider instance to a delegating one considering both AnnotationLinkRelationProvider and EvoLinkRelationProvider so that @relation annotations on entity types.
odrotbohm added a commit that referenced this issue Feb 18, 2021
Deprecated configuration methods on RepositoryRestConfiguration for better naming.
odrotbohm added a commit that referenced this issue Feb 18, 2021
…relation.

RepositoryRestConfiguration now defaults the LinkRelationProvider instance to a delegating one considering both AnnotationLinkRelationProvider and EvoLinkRelationProvider so that @relation annotations on entity types.
odrotbohm added a commit that referenced this issue Feb 18, 2021
…relation.

RepositoryRestConfiguration now defaults the LinkRelationProvider instance to a delegating one considering both AnnotationLinkRelationProvider and EvoLinkRelationProvider so that @relation annotations on entity types.
@odrotbohm
Copy link
Member

Fixed for 3.5, 3.4 and 3.3.

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

5 participants