0

我正在開發spring引導應用程序。它連接Apache Cassandra DB。我在Cassandra中創建了UDT。同時嘗試使用CassandraOperations保存數據。我得到例外。下面是Cassandra UDT的示例。Cassandra UDT VerifierMappingExceptions

http://www.devjavasource.com/cassandra/cassandra-udts-java-example/

卡桑德拉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] 

訂單行的Java類只有@UDT沒有@Table,@Persistent或@PrimaryKeyClass註釋

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

Spring Data Cassandra不支持Datastax的映射註釋。

UDT對Spring Data的支持Cassandra即將與https://github.com/spring-projects/spring-data-cassandra/pull/84合併。

您可以指定UDT與@UserDefinedType和使用UDTValue

@UserDefinedType 
public class Address { 
    String city; 
    String country; 
} 

@Table 
public class Person { 

    @Id String id; 
    Address address; 
    UDTValue genericUdt; 
} 

期待春天的數據卡珊德拉1.5被釋放今年年底(見https://github.com/spring-projects/spring-data-commons/wiki/Release-Train-Ingalls

+0

我無法找到合適的依賴關係。我更新了pom.xml。你能否糾正我的pom.xml來解決我的問題。謝謝 – Gnana

+0

由於構建了「SNAPSHOT」,UDT支持尚不可用。 – mp911de

+0

是否可以在UDT上用Cassandra開發彈簧?或不可能。你能幫我解決這個問題嗎?我是卡桑德拉的新春 – Gnana

0

我用映射的概念。它運作良好。我在網址後面跟着解決了我的問題。

https://datastax.github.io/java-driver/2.1.7/features/object_mapper/using/ 

https://datastax-oss.atlassian.net/browse/JAVA-590