我有以下POJO:

@Table(name = "order", readConsistency = "QUORUM", writeConsistency = "QUORUM")
public class Order {

    @Column(name = "id")
    @PartitionKey
    private String id;

    @Column(name = "customer_id")
    private String customerId;

    @Column(name = "loyalty_id")
    private String loyaltyId;

    @Column(name = "customer_email")
    private String customerEmail;

    public Order() {

    }
    ... getters and setters
}
现在,我将OrderDao编写如下:
    import com.datastax.oss.driver.api.mapper.annotations.*;

    @Dao
    public interface OrderDao {
            @Select
            Order findById(String orderId);

            @Insert
            void save(Order order);

            @Delete
            void delete(Order order);
    }
当我执行./gradlew build时,出现以下错误:
error: Invalid return type: Select methods must return one of [ENTITY, OPTIONAL_ENTITY, FUTURE_OF_ENTITY, FUTURE_OF_OPTIONAL_ENTITY, PAGING_ITERABLE, FUTURE_OF_ASYNC_PAGING_ITERABLE]
    Order findById(String orderId);
error: Insert methods must take the entity to insert as the first parameter
    void save(Order order);
         ^
error: Missing entity class: Delete methods that do not operate on an entity instance must have an 'entityClass' argument
    void delete(Order order);
         ^
我通过遵循此处的文档https://docs.datastax.com/en/developer/java-driver/4.2/manual/mapper/来实现。这可能是什么原因?
谢谢。

最佳答案

您缺少@Entity类上的Order批注:

@Entity
@Table(name = "order", readConsistency = "QUORUM", writeConsistency = "QUORUM")
public class Order {

关于java - 我正在尝试使用Datastax 4.2.2编写DAO接口(interface),但遇到一些编译错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/63114891/

10-11 22:38