spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
764 stars 344 forks source link

Spring Data JDBC - Sort.by does not work on nested @Embedded property #1758

Closed aveilleux closed 3 months ago

aveilleux commented 6 months ago

Hi,

Similar to this old issue https://github.com/spring-projects/spring-data-relational/issues/1286, I have another use case that doesn't seem to work for a nested @Embedded sort.

To summarize the use case with an example:

@Entity
class MyTable(
    @OneToOne
    MyTableDetails tableDetails;
    .....
)
@Entity
class MyTableDetails(
    @Embedded
    MoreEmbeddedDEtails moreDetails;
   ....
)
@Embeddable
class MoreEmbeddedDEtails(
    string simpleDetail
)

So when I try to sort on my MyTable, it looks like Sort.by("tableDetails.moreDetails.simpleDetail").ascending(), but I got an error similar to this one:

Caused by: java.lang.IllegalArgumentException: Unable to locate Attribute with the the given name [moreDetails.simpleDetail] on this ManagedType [MyTableDetails]

Currently using version spring-data-commons-2.7.18.

Thanks

schauder commented 3 months ago

Are we talking about Spring Data JDBC? Because you use @Embeddable which is not a Spring Data JDBC annotation and @Embedded can not be used without value for oneEmpty. This looks like Spring Data JPA to me.

In either case please provide a Minimimal Reproducable Example, preferable as a Github repository. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.

spring-projects-issues commented 3 months ago

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

spring-projects-issues commented 3 months ago

Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue.