Reputation: 2230
I am developing spring boot application. it connects Apache Cassandra DB. I have created UDT in Cassandra. while trying to save data using CassandraOperations. I am getting exception. I have followed below example for Cassandra UDT.
http://www.devjavasource.com/cassandra/cassandra-udts-java-example/
Cassandra DB: 2.1.11
Exception:
org.springframework.data.cassandra.mapping.VerifierMappingExceptions: com.lab.model.OrderLine:
Cassandra entities must have the @Table, @Persistent or @PrimaryKeyClass Annotation
at org.springframework.data.cassandra.mapping.BasicCassandraPersistentEntityMetadataVerifier.verify(BasicCassandraPersistentEntityMetadataVerifier.java:45) ~[spring-data-cassandra-1.4.3.RELEASE.jar:na]
OrderLine java class has only @UDT not @Table, @Persistent or @PrimaryKeyClass Annotation
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
@Table("order")
public class Order {
@PrimaryKeyColumn(name = "ord_id", ordinal = 0, type = PrimaryKeyType.PARTITIONED)
private int ord_id;
private List<OrderLine> order_line;
}
import java.util.UUID;
import com.datastax.driver.mapping.annotations.UDT;
@UDT(name = "order_line")
public class OrderLine {
private UUID po_line_nbr;
private int whpk_qty;
}
pom.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.4.1.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-cassandra</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
How to fix this issue.
Upvotes: 0
Views: 418
Reputation: 2230
I have used Mapper concept. it is working good. I have followed below URLs to resolve my issue.
https://datastax.github.io/java-driver/2.1.7/features/object_mapper/using/
https://datastax-oss.atlassian.net/browse/JAVA-590
Upvotes: 0
Reputation: 18119
Spring Data Cassandra does not support Datastax' mapping annotations.
UDT support for Spring Data Cassandra is about to get merged with https://github.com/spring-projects/spring-data-cassandra/pull/84.
You will be able to specify UDT's with @UserDefinedType
and to use UDTValue
@UserDefinedType
public class Address {
String city;
String country;
}
@Table
public class Person {
@Id String id;
Address address;
UDTValue genericUdt;
}
Expect Spring Data Cassandra 1.5 to be released end of this year (see https://github.com/spring-projects/spring-data-commons/wiki/Release-Train-Ingalls)
Upvotes: 0