我正在尝试使用 Datastax 4.2.2 编写 DAO 接口,但遇到了几个编译错误
I am trying to write a DAO interface using Datastax 4.2.2, but getting several compile errors
我有以下 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/。这可能是什么原因?
谢谢。
您在 Order
class 上缺少 @Entity
注释:
@Entity
@Table(name = "order", readConsistency = "QUORUM", writeConsistency = "QUORUM")
public class Order {
我有以下 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/。这可能是什么原因?
谢谢。
您在 Order
class 上缺少 @Entity
注释:
@Entity
@Table(name = "order", readConsistency = "QUORUM", writeConsistency = "QUORUM")
public class Order {