0

I am using

Java: 19

Springboot: 3.0

Dependency

<dependency>
      <groupId>org.springframework.data</groupId>
      <artifactId>spring-data-cassandra</artifactId>
 </dependency>

Entity class

@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Player {
  @PrimaryKey
  private UUID id;

Would like to know if there is anything like

@Id
@GeneratedValue(strategy = GenerationType.AUTO)

that we can use with it.

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105

2 Answers2

0

It can be achieved either using @CassandraType annotation in combination with the com.datastax.driver.core.DataType.Name.UUID

@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Player {
  @PrimaryKey
  @CassandraType(type = DataType.Name.UUID)
  private UUID id;

or @CassandraType annotation with the com.datastax.driver.core.DataType.Name.TIMEUUID

@Table
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Player {
  @PrimaryKey
  @CassandraType(type = DataType.Name.TIMEUUID)
  private UUID id;
Raushan Kumar
  • 1,195
  • 12
  • 21
  • `@CassandraType(type = DataType.Name` Name is not available for import, already tried this one. – Prafulla Kumar Sahu Jan 04 '23 at 13:10
  • check this file have definition-->CassandraRowMapperFn.java – Raushan Kumar Jan 04 '23 at 13:23
  • Can you please let me know your dependency seems you are using different package my DataType class is under `import com.datastax.oss.driver.api.core.type.DataType;` – Prafulla Kumar Sahu Jan 04 '23 at 13:29
  • https://docs.datastax.com/en/drivers/java/2.0/overview-summary.html package:com.datastax.driver.core it's DataStax Java Driver for Apache Cassandra - Binary distribution 2.0.12 API – Raushan Kumar Jan 04 '23 at 13:34
  • It needs another package `cassandra-driver-mapping` and that will change all the other syntax in my entity class. – Prafulla Kumar Sahu Jan 04 '23 at 13:55
  • `Incompatible types. Found: 'com.datastax.driver.core.DataType.Name', required: 'org.springframework.data.cassandra.core.mapping.CassandraType.Name'` the below option what I have posted is working, but still tried your version with `.cassandra.core.mapping` package and still getting this error, do you have any information which may help on it? – Prafulla Kumar Sahu Jan 12 '23 at 08:23
0
@CassandraType(type = DataType.Name.TIMEUUID)

is not auto generating the id.

One way is assigning default during declaration value like

 private UUID id = UUID.randomUUID();

but still, I consider this as a workaround.

Prafulla Kumar Sahu
  • 9,321
  • 11
  • 68
  • 105