英文:
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() {
}
... 获取器和设置器
}
现在我正在编写如下的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: 无效的返回类型:Select 方法必须返回 [ENTITY、OPTIONAL_ENTITY、FUTURE_OF_ENTITY、FUTURE_OF_OPTIONAL_ENTITY、PAGING_ITERABLE、FUTURE_OF_ASYNC_PAGING_ITERABLE] 中的一个
Order findById(String orderId);
error: Insert 方法必须将要插入的实体作为第一个参数
void save(Order order);
^
error: 缺少实体类:不操作实体实例的 Delete 方法必须有一个 'entityClass' 参数
void delete(Order order);
^
我正在按照这里的文档进行实现:https://docs.datastax.com/en/developer/java-driver/4.2/manual/mapper/ 。可能的原因是什么?
谢谢。
英文:
I have the following 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
}
And now I am writing the OrderDao as following:
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);
}
And when I do ./gradlew build
I get the following errors:
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);
^
I am implementing by following the documentation here: https://docs.datastax.com/en/developer/java-driver/4.2/manual/mapper/ . What could be the possible cause of this?
Thanks.
答案1
得分: 2
你的Order
类缺少@Entity
注解:
@Entity
@Table(name = "order", readConsistency = "QUORUM", writeConsistency = "QUORUM")
public class Order {
英文:
You are missing the @Entity
annotation on your Order
class:
@Entity
@Table(name = "order", readConsistency = "QUORUM", writeConsistency = "QUORUM")
public class Order {
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论