有人可以帮助我找出如何使用Spring
POJO类插入Cassandra UDT数据吗?
我创建了一个POJO类来映射Cassandra的表并为Cassandra UDT创建另一个类,但是当我插入映射Cassandra表的主POJO类时,它不能识别另一个POJO类(映射Cassandra的UDT)。我还在每个类和每个类对象上写了一个anotation。
这是我的一个POJO课程: -
package com.bdbizviz.smb.model.entity;
import org.springframework.cassandra.core.PrimaryKeyType;
import org.springframework.data.cassandra.mapping.PrimaryKeyColumn;
import org.springframework.data.cassandra.mapping.Table;
import com.bdbizviz.smb.cassandra.udt.CoverPhoto;
import com.bdbizviz.smb.cassandra.udt.Location;
import com.bdbizviz.smb.cassandra.udt.MailingAddress;
import com.bdbizviz.smb.cassandra.udt.Reference;
import com.bdbizviz.smb.cassandra.udt.RestaurantServices;
import com.bdbizviz.smb.cassandra.udt.RestaurantSpecial;
import com.bdbizviz.smb.cassandra.udt.VoipInfo;
import com.datastax.driver.mapping.annotations.Frozen;
@Table("source")
public class Sources {
Integer likes;
Integer followers;
Integer rating;
String last_processedtime;
String filter_str;
String filter_type;
String category;
@PrimaryKeyColumn(ordinal=0,type=PrimaryKeyType.PARTITIONED)
String admin;
@PrimaryKeyColumn(ordinal=1,type=PrimaryKeyType.CLUSTERED)
String name;
@PrimaryKeyColumn(ordinal=2,type=PrimaryKeyType.CLUSTERED)
String source;
@PrimaryKeyColumn(ordinal=3,type=PrimaryKeyType.CLUSTERED)
Integer id;
@PrimaryKeyColumn(ordinal=4,type=PrimaryKeyType.CLUSTERED)
String type;
Integer delete_flag;
Integer evaluated;
@Frozen
Reference fb_reference_id_name ;
@Frozen
MailingAddress fb_mailingaddress;
@Frozen
CoverPhoto fb_coverphoto ;
@Frozen
VoipInfo fb_voipinfo;
@Frozen
RestaurantServices fb_restaurantservice;
@Frozen
RestaurantSpecial fb_restaurantspecialties;
@Frozen
Location fb_location;
/* Setter and Getter */
}
另一个POJO课程: -
package com.bdbizviz.smb.cassandra.udt;
import org.springframework.data.annotation.Persistent;
import com.datastax.driver.mapping.annotations.Field;
import com.datastax.driver.mapping.annotations.UDT;
@UDT(name = "reference" ,keyspace="smb")
public class Reference {
@Field(name="id")
String id ;
@Field(name="name")
String name;
/* Setter and Getter */
}
答案 0 :(得分:2)
Spring Cassandra Driver甚至不支持UDT功能。您必须使用Cassandra的自定义驱动程序才能使用此功能。
这是Cassandra Driver的maven依赖
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-dse</artifactId>
<version>2.1.6</version>
</dependency>
答案 1 :(得分:0)
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-mapping</artifactId>
<version>2.1.9</version>
</dependency>
需要