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

@ReadingConverter is not work,and does R2DBC have the right way to implement one to many? #678

Closed
wang-xiaowu opened this issue Nov 6, 2021 · 1 comment
Assignees
Labels
status: duplicate A duplicate of another issue

Comments

@wang-xiaowu
Copy link

  • AttrValueConverter
@ReadingConverter
public class AttrValueConverter implements Converter<Row, Attr> {
    @Override
    public Attr convert(Row source) {
        Attr attr = new Attr();
        attr.setAttrId(source.get("attrId",Long.class));
        attr.setShopId(source.get("shopId",Long.class));
        attr.setName(source.get("name",String.class));
        attr.setDesc(source.get("desc",String.class));
        attr.setSearchType(source.get("searchType",Integer.class));
        attr.setAttrType(source.get("attrType",Integer.class));
        attr.setCreateBy(source.get("createBy",String.class));
        attr.setUpdateBy(source.get("updateBy",String.class));
        attr.setCreateTime(source.get("createTime", LocalDateTime.class));
        attr.setUpdateTime(source.get("updateTime",LocalDateTime.class));
//        List<AttrValue> attrValues = source.get("attrValues", List.class);
//        for (AttrValue attrValue : attrValues) {
//        }
        AttrValue attrValue = new AttrValue();
        attrValue.setAttrValueId(source.get("attrValueId",Long.class));
        attrValue.setAttrId(source.get("attrId",Long.class));
        attrValue.setValue(source.get("value",String.class));
        attrValue.setCreateBy(source.get("String",String.class));
        attrValue.setUpdateBy(source.get("updateBy",String.class));
        attrValue.setCreateTime(source.get("createTime",LocalDateTime.class));
        attrValue.setUpdateTime(source.get("updateTime",LocalDateTime.class));
        attr.setAttrValues(attrValue);
        return attr;
    }
}
  • config
@Configuration
@RequiredArgsConstructor
public class MyAppConfig extends AbstractR2dbcConfiguration {

  private final ConnectionFactory connectionFactory;

  @Override
  public ConnectionFactory connectionFactory() {
    return connectionFactory;
  }

  @Override
  @Bean
  public R2dbcCustomConversions r2dbcCustomConversions() {
    List<Converter<?, ?>> converterList = new ArrayList<Converter<?, ?>>();
    converterList.add(new AttrValueConverter());
    return new R2dbcCustomConversions(getStoreConversions(), converterList);
  }
}
  • Attr
@Data
@EqualsAndHashCode(callSuper = true)
@Table
public class Attr extends BaseEntity implements Serializable{
    private static final long serialVersionUID = 1L;

	/**
     * attr id
     */
    private Long attrId;

    private AttrValue attrValues;
...

  • AttrValue
@Data
@EqualsAndHashCode(callSuper = true)
@Table
public class AttrValue extends BaseEntity implements Serializable{
    private static final long serialVersionUID = 1L;
   ...
}
  • AttrRepository
public interface AttrRepository extends R2dbcRepository<Attr, Long> {

    @Query("select a.*,av.* from attr a join attr_value av on a.attr_id = av.attr_id")
    Flux<Attr> findAttrAndValues();
}
@wang-xiaowu wang-xiaowu changed the title @ReadingConverter is not work @ReadingConverter is not work,and does R2DBC have the right way to implement one to many? Nov 6, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 6, 2021
@christophstrobl christophstrobl removed the status: waiting-for-triage An issue we've not yet triaged label Nov 8, 2021
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Nov 8, 2021
@mp911de
Copy link
Member

mp911de commented Nov 9, 2021

List<AttrValue> attrValues = source.get("attrValues", List.class); won't work because R2DBC doesn't support embedded lists. Closing this a duplicate of #356.

@mp911de mp911de closed this as completed Nov 9, 2021
@mp911de mp911de added status: duplicate A duplicate of another issue and removed status: waiting-for-triage An issue we've not yet triaged labels Nov 9, 2021
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