spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

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

Open aveilleux opened this issue 1 year ago • 2 comments
trafficstars

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

aveilleux avatar Mar 27 '24 19:03 aveilleux

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.

schauder avatar Jun 24 '24 11:06 schauder

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 avatar Jul 01 '24 11:07 spring-projects-issues

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.

spring-projects-issues avatar Jul 08 '24 11:07 spring-projects-issues