Hi Frank,
It's a very good question :) MongoDB does not offer multi-document transactions (at least < MongoDB 3.0; I think they have some kind of support there, but we don't take advantage of that yet; Would need to take a closer look to see what's possible now), so Hibernate OGM cannot roll back "transactions".
Still Hibernate OGM uses transaction boundaries (either marked explicitly e.g. via entityManager.getTransaction().begin()/commit() or implicitly e.g. in an EJB with transactions managed by the application server) to collect changes and send them to the datastore in batches, in an optimized manner. E.g. we will only persist the end state of an entity after several intermediary changes, we will use bulk APIs for inserts etc.
Using transaction-type=JTA will give you implicit management of such "work units" done by the container (either through EJBs or CDI and @Transactional methods). In Java SE it doesn't really matter whether you use JTA or RESOURCE_LOCAL.
Of course this raises the question what happens in case an exception happens during persisting such a batch of changes and e.g. some changes already have been written to the data store. If the datastore does not support transactions, we cannot do a rollback. For such cases, we provide a new API as of Hibernate OGM 4.2 which allows you to register error handlers and e.g. log applied operations and perform a manual undo later on. The blog post http://in.relation.to/Bloggers/HibernateOGMErrorHandlingOnNontransactionalNoSQLStores has more details on that, any feedback on this (or any other questions around OGM) is highly welcome.
Hth,
--Gunnar
_________________ Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/
|