Closed
Description
Hello, I am using Spring Data R2DBC and I found that the mapping "feature" that I used for one-to-one connections stopped working.
For example
create table users (id uuid not null primary key, username varchar(50) not null);
create table users_descriptions (user_id uuid not null primary key, name varchar(100) not null, phone varchar(13));
Entities
@Table("users")
data class UserEntity(val username: String, @Id val id: UUID = UUID.randomUUID())
@Table("users_descriptions")
data class UserDescriptionEntity(val name: String, val phone: String, @Id val userId: UUID)
data class UserWithDescriptionEntity(val username: String, val description: UserDescriptionEntity, val id: UUID)
Repo
@Repository
interface UserRepository: ReactiveCrudRepository<UserEntity, UUID> {
@Query("SELECT u.*, ud.user_id as description_user_id, ud.name as description_name, " +
"ud.phone as description_phone LEFT OUTER JOIN users_descriptions ud on ud.user_id = u.id")
fun <T> findAllExtended(type: Class<T>): Flux<T>
}
Usage
userRepository.findAll() -> Flux<UserEntity>
userRepository.findAllExtended(UserWithDescriptionEntity::class.java) -> Flux<UserWithDescriptionEntity>
After this commit automatic mapping nested entity in that way stopped working.
As far as I understand, the readEntityFrom function takes the current field from the parent Entity as a prefix and further searches by Row using this prefix for the fields of the nested Entity, but now this function is not called if name of Entity field is not found in the metadata
I already found the workaround - just add something like this to the sql select statement true as description
, but maybe it should work differently?