Skip to content
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

r2dbc nested entity mapping #749

Closed
alim-zanibekov opened this issue Mar 31, 2022 · 3 comments
Closed

r2dbc nested entity mapping #749

alim-zanibekov opened this issue Mar 31, 2022 · 3 comments
Labels
status: duplicate A duplicate of another issue

Comments

@alim-zanibekov
Copy link

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?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 31, 2022
@mp911de
Copy link
Member

mp911de commented Apr 1, 2022

Nested entities were never intended to work because we do not yet have proper fetching strategies in place. We are working towards a solution, but for the time being, closing this one.

@mp911de mp911de closed this as completed Apr 1, 2022
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Apr 1, 2022
@mp911de
Copy link
Member

mp911de commented Apr 1, 2022

Duplicate of #695

@mp911de mp911de marked this as a duplicate of #695 Apr 1, 2022
@frreynal
Copy link

same error here, any updates ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: duplicate A duplicate of another issue
Projects
None yet
Development

No branches or pull requests

4 participants