Spring-cassandra UDT data insertion
Can anyone help me learn how to insert Cassandra UDT data using the Spring
POJO class ?
I created one POJO class to display the Cassandra table and created another class for the Cassandra UDT, but when I inserted the main POJO class that displays the Cassandra table it did not recognize the other POJO class (Cassandra UDT map). I also wrote an annotation for each class and for each class object.
Here is my POJO class: -
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 */
}
Another POJO class: -
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 */
}
+3
source to share
2 answers
Spring Cassandra driver doesn't even support UDT feature. You must use the native Cassandra driver for this function.
Here is the maven dependency for the Cassandra driver
<dependency>
<groupId>com.datastax.cassandra</groupId>
<artifactId>cassandra-driver-dse</artifactId>
<version>2.1.6</version>
</dependency>
+2
source to share