0

我尝试在示例应用程序中使用 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;

数据.sql:

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

我使用 aResourceDatabasePopulator来填充数据,它可以工作。

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

@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, AMOUNT) VALUES (?, ?)'
    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]

完整的代码在这里

更新:放弃扩展AbstractR2dbcConfiguration,按照官方指南解决。

4

0 回答 0