微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Spring Data R2dbc中带有postgres的数值类型映射问题

如何解决Spring Data R2dbc中带有postgres的数值类型映射问题

我尝试在示例应用程序中使用Spring Data R2dbc / Postgres。

  • Spring Boot 2.4.0-M2
  • R2dbc Postgres(由Spring Boot管理)
  • Spring Data R2dbc 1.2.0-M2(由Spring Boot管理)

表脚本。


CREATE SEQUENCE IF NOT EXISTS ORDERS_ID_SEQ;

CREATE TABLE  IF NOT EXISTS ORDERS(
ID INTEGER NOT NULL PRIMARY KEY DEFAULT nextval('ORDERS_ID_SEQ'),CUST_ID BIGINT NOT NULL,AMOUNT REAL NOT NULL
);

ALTER SEQUENCE ORDERS_ID_SEQ OWNED BY ORDERS.ID;

data.sql

-- INSERT SAMPLE DATA
DELETE FROM ORDERS;
INSERT INTO ORDERS(CUST_ID,AMOUNT) VALUES (1,100.2);

我使用ResourceDatabasePopulator填充数据,它可以正常工作。

但是当我尝试通过存储库保存数据时,失败了。

@Table(value = "ORDERS")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Order implements Serializable {

    @Id
    @Column(value = "ID")
    private Integer id;

    @Column(value = "CUST_ID")
    private Long customerId;

    // use BigDecimal or Java Money API in the real-world application.
    @Column(value = "AMOUNT")
    private Double amount;
}


public interface OrderRepository extends R2dbcRepository<Order,Integer> {
}

// in application runner.

orders .save(Order.builder().customerId(c.getId()).amount(201.0).build())

它抛出了这样的异常:

reactor.core.Exceptions$ErrorCallbackNotImplemented: java.lang.UnsupportedOperationException: Binding parameters is not supported for the statement 'INSERT INTO ORDERS (CUST_ID,AMOUNT) VALUES (?,?)'
Caused by: java.lang.UnsupportedOperationException: Binding parameters is not supported for the statement 'INSERT INTO ORDERS (CUST_ID,?)'
    at io.r2dbc.postgresql.SimpleQueryPostgresqlStatement.bind(SimpleQueryPostgresqlStatement.java:78) ~[r2dbc-postgresql-0.8.4.RELEASE.jar:0.8.4.RELEASE]
    at io.r2dbc.postgresql.SimpleQueryPostgresqlStatement.bind(SimpleQueryPostgresqlStatement.java:44) ~[r2dbc-postgresql-0.8.4.RELEASE.jar:0.8.4.RELEASE]

完整代码here

已更新:从AbstractR2dbcConfiguration开始放弃,并在跟随the official guide时被抢救。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。