Reputation: 255
I am using Spring and Cassandra as the underlying database. Had referred to the spring umbrella project 'spring data cassandra'. Could not find out how transactions are managed here unlike hibernate. Kindly share the details for the Transaction Manager to be included if some of you have incorporated the same.
Upvotes: 4
Views: 7810
Reputation: 1907
Cassandra batch is currently atomic by default. http://docs.datastax.com/en/cql/3.0/cql/cql_reference/batch_r.html
So it is , probably, the best equivalent to @Transactional in spring data (Although, full ACID is not for this world, it is just not that way it plays)
Something like this should play(YOU can change values of ConsistencyLevel and RetryPolicy as you wish - that is the matter!):
Insert insert1 = CassandraTemplate.createInsertQuery("table1", value1, new WriteOptions(ConsistencyLevel.LOCAL_ONE, RetryPolicy.DEFAULT), cassandraConverter);
Insert insert2 = CassandraTemplate.createInsertQuery("table2", value2, new WriteOptions(ConsistencyLevel.LOCAL_ONE, RetryPolicy.DEFAULT), cassandraConverter);
Batch batch = QueryBuilder.batch(insert1,insert2);
//cassandraOperations - object of CassandraTemplate , injected by Spring
cassandraOperations.execute(batch);
Upvotes: 5
Reputation: 3035
Cassandra does not support transactions in the traditional (ACID) sense. There are a few constructs where you can achieve something like transactional atomicity in special cases, like atomic batches (see http://www.datastax.com/dev/blog/atomic-batches-in-cassandra-1-2) or Lightweight Transactions (see http://www.datastax.com/dev/blog/lightweight-transactions-in-cassandra-2-0), but nothing that lends itself to a full-blown transaction management.
This is mostly the result of the architecture of Cassandra, which focuses on scalability and fault tolerance on a level not possible with traditional relational databases.
Upvotes: 5