Abhilash
Abhilash

Reputation: 895

How to map user data type in cassandra using spring boot data

I am looking out for some help related with spring boot data using Cassandra database.
I have following dependencies in my pom.xml.

        <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 

i get below error: Cassandra entities must have the @Table, @Persistent or @PrimaryKeyClass Annotation

Upvotes: 0

Views: 1926

Answers (1)

mp911de
mp911de

Reputation: 18119

Spring Data for Apache Cassandra and Datastax' Mapping are two independent tools that try to accomplish the same. Please use either one but don't mix these.

CrudRepository is a Spring Data type while @Field and @UDT are coming from Datastax Mapping.

UDT support for Spring Data for Apache Cassandra is available as of version 1.5, see reference docs. Spring Data for Apache Cassandra 1.5 requires Datastax Java Driver 3.0 or newer.

Upvotes: 1

Related Questions