Search code examples
javacassandracql3datastaxdatastax-java-driver

DataStax accessor bean as bind param


I am trying to use a datastax accessor (vs using a mapper).

My accessor is defined as follows:

@Accessor
public interface TableAccessor {
    @Query(
        "INSERT INTO tableName " +
        "(id, data)" +
        "VALUES (:beanId, :beanData)")
    public ResultSet insertProblem(@Param("bean") Bean bean);

And my bean is defined as.

@Table(name="tableName")
public class Bean {
    @PartitionKey
    @Column(name = "id")
    private int beanId;

    @PartitionKey
    @Column(name = "data")
    private Date beanData;

   // Setters and getters omitted 
}

My issues is when I try something like:

insertProblem(@Param("bean") Bean bean)

I keep getting errors telling me my param numbers don't match.


Solution

  • I am not sure that is even possible, to send object and to map properties of that object (maybe some dot notation but haven't check code or documentation). Maybe your notation would work if you work with UDT and you have Bean as UDT in DB.

    What works for sure is:

    @Accessor
    public interface TableAccessor {
        @Query(
            "INSERT INTO tableName " +
            "(id, data)" +
            "VALUES (:beanId, :beanData)")
        public ResultSet insertProblem(@Param("beanId") int beanId, @Param("beanData") Date beanData);
    

    And yhan you call method with insertProblem(bean.getBeanId(), bean.getBeanData())