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

Multi table Association result set

Open ChenZheOnePiece opened this issue 4 years ago • 0 comments

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

ChenZheOnePiece avatar Oct 14 '20 02:10 ChenZheOnePiece