Burhan avatar image
Burhan asked Erick Ramirez commented

Batch execution only updates data and does not insert new data

Hi Dev's,

Below is my code

BatchStatement batch = BatchStatement.newInstance(BatchType.UNLOGGED).addAll(list);


where list is an ArrayList of PreparedStatements containing Insert queries

As insert is an upsert operation, so it updates an already existing record, but for a new record, it does not perform an insert nor does nit throw any exception/error

There are 2 tables in cassandra


Primary Key = (customerId, brand)


Primary Key = (customerId, brand, name, version)

These tables contains UDT columns as well.

The Batch Execution will contain 1 customer insert/update and multiple campaign insert/update statements

The main intention is to achieve atomicity which ensures that if any one statement fails then it will fail the entire batch

10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

1 Answer

Erick Ramirez avatar image
Erick Ramirez answered Erick Ramirez commented

You won't be able to achieve atomicity because you've configured your batches to be UNLOGGED. The all-or-none guarantee only exists with LOGGED batches.

Why new data isn't inserted, I can't tell because I don't have enough information. My hypothesis is that you haven't constructed the statements correctly so the data isn't getting inserted as you expected. Cheers!

2 comments Share
10 |1000

Up to 8 attachments (including images) can be used with a maximum of 1.0 MiB each and 10.0 MiB total.

Burhan avatar image Burhan commented ·

Hi @Erick Ramirez,

Thanks a lot for replying. When I use Logged batches, it gives me the below error

"Logged batches are not supported for this type of batch requests"

Any idea why I am facing this?

Thanks & Regards,


0 Likes 0 ·
Erick Ramirez avatar image Erick Ramirez ♦♦ Burhan commented ·

Asked and answered in question #13493. Cheers!

0 Likes 0 ·