我正尝试使用 Datastax 4.2.2 编写 DAO 接口,但是遇到了多个编译错误。

huangapple go评论88阅读模式
英文:

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 {   

huangapple
  • 本文由 发表于 2020年7月27日 20:00:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/63114891.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定