Skip to content

Multi table Association result set #480

Open
@ChenZheOnePiece

Description

@ChenZheOnePiece

i have user role role_user tables, i want Simultaneous query user and role by one sql after encapsulation int DTO.but beacuse User and DTO properties is not same,so java.lang.IllegalArgumentException: Property must not be null!.I want to know how to do

    @Query("select u.id ,u.name,u.age as age, r.role_name  from user " +
            "u left join role_user ur on u.id=ur.user_id " +
            "left join role r on ur.role_id=r.id" +
            " where 1=1 and (:#{#user.name} is null or u.name = :#{#user.name}) " +
            " LIMIT :#{#page},:#{#size}")
    Flux<RoleUserDto> joinPage(@Param("user") User user, @Param("page") int page, @Param("size") int size);

if i have User like this , Can the above queries be encapsulated directly into user objects

@Data
@AllArgsConstructor
@NoArgsConstructor
@Table(value = "user")
public class User {
    @Id
    private String id;
    private String name;
    private Integer age;
    private byte[] content;
    private LocalDateTime createdDate;
    private LocalDateTime modifiedDate;
    private List<Role> role;

}

I uploaded my project , my test UserControllerTest . joinPage method Tested what I said above. i think spring-data-examples/r2dbc/ is Incomplete . Can I contribute to my project . Please take a look at it for me. Thank you very much.

https://github.com/ChenZheOnePiece/webflux-r2dbc

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @spring-projects-issues@ChenZheOnePiece

        Issue actions

          Multi table Association result set · Issue #480 · spring-projects/spring-data-r2dbc