An issue with mapping an @Embeded object with cassandra spring data

15 Views Asked by At

I am using Spring Boot v3.2.2 with data Cassandra.

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

I am trying to use an Embedded object. Here is the code of my entity

@Table("switch_by_country_customer_department_controller")
public class Switch implements Persistable<SensorId> {

    @PrimaryKey
    private SensorId id;

    @Embedded(onEmpty = OnEmpty.USE_EMPTY)
    private DeviceInfo deviceInfo;
    ...
}

And the Embedded object class

    public class DeviceInfo {
    
        private String producer;
    
        private String model;
    
        private String sn;
    
        private String mac;
        ...
   }

Once I try to insert something into this table I receive the following exception. Which is a bit funny as I would not expect any column with the name deviceinfo as this is a name of the embedded object property in the Switch class

Query; CQL [INSERT INTO switch_by_country_customer_department_controller (country,customer,department,sensorcode,controllercode,deviceinfo,registrationdate,activationdate) VALUES (?,?,?,?,?,?,?,?)]; Undefined column name deviceinfo in table pflanze.switch_by_country_customer_department_controller

An interesting fact is that the automatically generated schema looks fine and the application is correct here: no such field

 CREATE TABLE pflanze.switch_by_country_customer_department_controller ( 
    country              TEXT   ,
    customer             TEXT   ,
    department           TEXT   ,
    sensorcode           TEXT   ,
    controllercode       TEXT   ,
    activationdate       TIMESTAMP   ,
    mac                  TEXT   ,
    model                TEXT   ,
    producer             TEXT   ,
    registrationdate     TIMESTAMP   ,
    sn                   TEXT   ,
    PRIMARY KEY( (country, customer, department), sensorcode, controllercode )
 )

And even more interesting is the fact if I give the embedded object field the name of any member of the embedded object itself, like this:

@Table("switch_by_country_customer_department_controller")
public class Switch implements Persistable<SensorId> {

    @PrimaryKey
    private SensorId id;

    @Embedded(onEmpty = OnEmpty.USE_EMPTY)
    private DeviceInfo model;
...
}

The logic works as expected and all the data is inserted in the right columns.

Does someone faced the same issue? It looks like a bug. Can somebody confirm?

Thanks

0

There are 0 best solutions below