0

I'm trying to use Kundera as a JPA implementation over cassandra (namely for the transaction management capabilities).

2 questions:

FIRST QUESTION

is it true that transaction management does not support native queries? i.e. if I do:

EntityManagerFactory emf = Persistence.createEntityManagerFactory("piccandra", getCassandraProperties());

EntityManager em = emf.createEntityManager();
em.setFlushMode(FlushModeType.COMMIT); 
em.getTransaction().begin();
Query q = em.createNativeQuery("insert into photographer (photographer_id, photographer_name) values ('id1', 'name1')");
q.executeUpdate();
em.getTransaction().rollback();

the rollback will not work?

SECOND QUESTION

how do I perform optimistic locking (aka CAS) on persist? In cassandra I can run:

UPDATE photographer SET name = 'x' WHERE id = 1 AND update_date <= some-timestamp

When using Kundera I want to persist an entity only if it hasn't changed by someone else on the base store. can I do that?

EDIT: I see that JPA does support optimistic locking, but Kundera does not imeplement it.

asafd
  • 315
  • 4
  • 14
  • Why would you use a NATIVE query if you want optimistic handling? Makes no sense. Optimistic handling is when using the persistence API –  May 25 '16 at 14:03
  • if I could use native queries I could use the statement from the question to handle the locking. I actually prefer not to use the persistence API exactly because of such limitations. – asafd May 25 '16 at 14:32

1 Answers1

0
  • Rollbacks will not work in case of native queries, as there is no entity object mapped to the query is available in persistence context (required for maintaining the state of the object in transactions).

  • Kundera does not support optimistic locking as of now. If you are looking for a workaround you can use native querying on Cassandra.

karthik manchala
  • 13,492
  • 1
  • 31
  • 55