java-driver icon indicating copy to clipboard operation
java-driver copied to clipboard

Insert with ifNotExists not working correctly

Open mtillberg opened this issue 1 year ago • 0 comments

When using the DAO mapper to create a method in the form:

@Insert(ifNotExists = true)
Object save(Object obj);

When a new record is inserted, an Object is returned with null for all fields, rather than returning null as expected from the documentation. The issue seems to be in com.datastax.oss.driver.internal.mapper.DaoBase.asEntity(). The check for returning null includes row.getColumnDefinitions().size() == 1, however what's in the Row is the expected '[applied]' column along with columns for each field in the table with null values. Additionally, the '[applied]' column exists regardless of whether the row was inserted or not so it may be better to check the value of the applied column rather than rely on the column count.

This was seen with java-driver-core and java-driver-mapper-runtime v4.17.0.0 against Scylla 5.4.6-0.20240418.10f137e367e3 from Docker.

mtillberg avatar May 13 '24 18:05 mtillberg