我正在开发spring boot应用程序。它连接Apache Cassandra DB。我在Cassandra创建了UDT。尝试使用CassandraOperations保存数据时。我越来越异常了。我已经按照以下示例了解了Cassandra UDT。
http://www.devjavasource.com/cassandra/cassandra-udts-java-example/
Cassandra DB :2.1.11
例外:
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类只有@UDT而不是@ Table,@ Persistent或@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>
如何解决此问题。
答案 0 :(得分:0)
Spring Data Cassandra不支持Datastax的映射注释。
对Spring Data Cassandra的UDT支持即将与https://github.com/spring-projects/spring-data-cassandra/pull/84合并。
您可以使用@UserDefinedType
指定UDT并使用UDTValue
@UserDefinedType
public class Address {
String city;
String country;
}
@Table
public class Person {
@Id String id;
Address address;
UDTValue genericUdt;
}
期待Spring Data Cassandra 1.5将于今年年底发布(见https://github.com/spring-projects/spring-data-commons/wiki/Release-Train-Ingalls)
答案 1 :(得分:0)
我使用过Mapper概念。它运作良好。我已按照以下网址解决了我的问题。
https://datastax.github.io/java-driver/2.1.7/features/object_mapper/using/
https://datastax-oss.atlassian.net/browse/JAVA-590