2
votes

Versions: Datastax Java driver 3.1.4, Cassandra 3.10

Consider the following table:

create table object_ta
(
  objid         bigint,
  version_date  timestamp,
  objecttype    ascii,
  primary key  (objid, version_date)
);

And a mapped class:

@Table(name = "object_ta")
public class ObjectTa
{
    @Column(name = "objid")
    private long objid;
    @Column(name = "version_date")
    private Instant versionDate;
    @Column(name = "objecttype")
    private String objectType;

    public ObjectTa()
    {
    }

    public ObjectTa(long objid)
    {
        this.objid = objid;
        this.versionDate = Instant.now();
    }

    public long getObjId()
    {
        return objid;
    }

    public void setObjId(long objid)
    {
        this.objid = objid;
    }

    public Instant getVersionDate()
    {
        return versionDate;
    }

    public void setVersionDate(Instant versionDate)
    {
        this.versionDate = versionDate;
    }

    public String getObjectType()
    {
        return objectType;
    }

    public void setObjectType(String objectType)
    {
        this.objectType = objectType;
    }
}

After creating a mapper for this class (mm is a MappingManager for the session on mykeyspace)

final Mapper<ObjectTa> mapper = mm.mapper(ObjectTa.class);

On calling

mapper.save(new ObjectTa(1));

I get

Query preparation failed: INSERT INTO mykeyspace.object_ta (objid,objid,version_date,objecttype) VALUES (?,?,?,?);: com.datastax.driver.core.exceptions.InvalidQueryException: The column names contains duplicates at com.datastax.driver.core.Responses$Error.asException(Responses.java:136) at com.datastax.driver.core.SessionManager$4.apply(SessionManager.java:220) at com.datastax.driver.core.SessionManager$4.apply(SessionManager.java:196) at com.google.common.util.concurrent.Futures$ChainingListenableFuture.run(Futures.java:906) at com.google.common.util.concurrent.Futures$1$1.run(Futures.java:635) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) at java.lang.Thread.run(Thread.java:745)

I am at a loss to understand, why the duplicate objid is generated in the query.

Thank you in advance for pointers to the problem.

Clemens

1

1 Answers

1
votes

I think it is because the inconsistent use of case on the field name (objid) vs the setter/getters (getObjId). If you rename getObjId and setObjId to getObjid and setObjid respectively, I believe it might work.

In a future release, the driver mapper will allow the user to be more explicit about whether setters/getters are used (JAVA-1310) and what the naming conventions are (JAVA-1316).