spring-data-relational
spring-data-relational copied to clipboard
Spring Data JDBC - Sort.by does not work on @Embedded property
Hi guys!
I'm trying to apply sorting in a Pageable, but there is no way to make it work for a property which is part of an @Embedded object.
Entities:
data class Account(
@Id
val id: Long?,
@Embedded.Nullable(prefix = "contact_")
val contact: Contact?,
)
data class Contact(
val name: String,
)
Sort:
Sort.by("contact.name").ascending()
Exception:
java.lang.IllegalStateException: Required property contact.name not found for class lms.model.Account!
at org.springframework.data.mapping.PersistentEntity.getRequiredPersistentProperty(PersistentEntity.java:161) ~[spring-data-commons-2.6.0.jar:2.6.0]
If the PersistentEntity.getRequiredPersistentProperty method doesn't know anything about the @Embedded annotation, I think the following method won't work and it could be the cause of the issue.
https://github.com/spring-projects/spring-data-relational/blob/a68409798468dee26d790dcb63367138a854681c/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/SqlGenerator.java#L718-L723
Should you use the SqlGenerator.getTable().column() method instead?