0
votes

I am using kundera-cassandra V3.2 and want to update an entity with the method merge.

this.getManager().merge(entity); // this.getManager is a javax.persistence.EntityManager

Is there a possibility to use a lightweight transaction (IF clause) when calling this method or do I have to create a update query manually?

1
if Kundera claims to be JPA compliant then you need a transaction around it tx.begin, tx.commit. - Neil Stockton
Thanks for the commet, but the lightweight transaction does not have to do anything with the jpa transaction management in my opinion. A lightweight transaction is used if you extend your query with an additional clause. My question: is there is any implementation from Kundera to add such a clause when calling the merge or persist method of EntityManager. - K.E.
what query? you have no query in what you posted. A merge will do "UPDATE ...", "DELETE ...", "INSERT ..." etc dependent on what you have changed in "entity" - Neil Stockton
I do not have query - and i do not need one. This was just to describe what is meant for a lightweight transaction in cassandra context. And sorry, "query" was maybe the wrong term -> "statement" is better - K.E.

1 Answers

2
votes

In Kundera, lightweight transactions are supported through createNativeQuery method. There is no direct method for merging with lightweight transactions.

Sample code:

String query = "UPDATE \"PERSONCASSANDRA\" SET \"PERSON_NAME\" = 'Pragalbh' WHERE \"PERSON_ID\" = '4' IF \"PERSON_NAME\" = 'Karthik'";
Query q = entityManager.createNativeQuery(query, PersonCassandra.class);
q.executeUpdate();

Please check this test-case for more information.