2017-04-21 45 views
0

我正在尋找與使用Cassandra數據庫的彈簧引導數據相關的一些幫助。
我在我的pom.xml中有以下依賴項。如何使用彈簧引導數據在cassandra中映射用戶數據類型

 <dependency> 
      <groupId>org.springframework.data</groupId> 
      <artifactId>spring-boot-starter-data-cassandra</artifactId> 
     </dependency> 

     <dependency> 
      <groupId>com.datastax.cassandra</groupId> 
      <artifactId>cassandra-driver-core</artifactId> 
      <version>2.1.10.3</version> 
     </dependency> 
     <dependency> 
      <groupId>com.datastax.cassandra</groupId> 
      <artifactId>cassandra-driver-mapping</artifactId> 
      <version>2.1.10.3</version> 
     </dependency> 

The table structure looks like: 

@Table(value = "TEST_ORDERS") 
public class OrderDTO { 

    @PrimaryKey 
    @Column(value = "email") 
    private String emailId; 

    @Column(value = "order_id") 
    private int orderId; 

    @Column(value = "creation_date") 
    private Timestamp creationDate; 

    @Column(value = "discount_total") 
    private double discountTotal; 

    @Column(name = "shipments") 
    //This is a UDT type 
    private Set<ShippingDetails> shipments; 

    //getters and setters here 
} 

The ShippingDetails object is a UDT with following declartion and i defined as a frozen collection in the cassandra CQL sripts 

@UDT(name = "shipping", keyspace = "mc_checkout") 
public class ShippingDetails { 

    @Field(name = "name") 
    private FullName name; 

    @Field(name = "quantity_shipped") 
    private int quantityShipped; 

    @Field(name = "shipping_address") 
    private CheckoutAddress shippingAddress; 
    //so on 
} 

There is a repository created for the basic CRUD operations: 
@Repository 
public interface OrderRepository extends CrudRepository<OrderDTO, String> { 

} 

    When i try to invoke findOne API of this repository in my Service class 

我得到以下錯誤: 卡桑德拉實體必須有@Table,@Persistent或@PrimaryKeyClass註釋

回答

1

春數據爲Apache Cassandra的和Datastax」測繪是試圖完成相同的兩個獨立的工具。請使用其中一種,但不要混用這些。

CrudRepository是一個Spring數據類型,而@Field@UDT來自Datastax映射。

對Apache Cassandra的Spring Data的UDT支持從版本1.5開始提供,請參閱reference docs。 Apache Cassandra 1.5的Spring Data需要Datastax Java Driver 3.0或更高版本。

相關問題