Hibernate Books

All times are UTC - 5 hours [ DST ]



Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: How does Hibernate OGM handle transactions for NoSQL DB?
PostPosted: Tue May 05, 2015 7:02 am 
Newbie

Joined: Fri May 01, 2015 1:38 pm
Posts: 3
Hi all!
I have started learning OGM deploying applications on an application server (WildFly).
I have some doubts about transactions: is it correct to define transaction type as JTA, when using MongoDB ?
<persistence-unit name="mongo-ogm" transaction-type="JTA">
. . .
</persistence-unit>
Also what's the sense of using JTA when MongoDB is not transactional ?
Will Hibernate OGM be able to rollback transactions on MongoDB somehow ?
Thanks


Top
 Profile  
 
 Post subject: Re: How does Hibernate OGM handle transactions for NoSQL DB?
PostPosted: Tue May 05, 2015 10:33 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
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/


Top
 Profile  
 
 Post subject: Re: How does Hibernate OGM handle transactions for NoSQL DB?
PostPosted: Thu May 07, 2015 2:16 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
There is also the FAQ on the subject for some additional info http://hibernate.org/ogm/faq/#how-does-hibernate-ogm-handle-transactions

Gunnar, maybe this FAQ entry should mention compensation?

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: How does Hibernate OGM handle transactions for NoSQL DB?
PostPosted: Thu May 07, 2015 7:25 am 
Hibernate Team
Hibernate Team

Joined: Sat Jan 24, 2009 12:46 pm
Posts: 386
Ah yes, good idea. I will add something.

_________________
Visit my blog at http://musingsofaprogrammingaddict.blogspot.com/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.