-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: How to rollback a list of object in a transaction
PostPosted: Tue Jan 13, 2015 11:29 am 
Newbie

Joined: Thu May 01, 2014 9:14 pm
Posts: 12
Hello;
i give you an example of my problem,
i have a list that contains 10000 object, i tried to commit this list in one transaction but the problem is for example if the object number 1000 that contains a duplicate key i find that transaction is rollback and the 999 first objects are persisted in the database.
i want a solution when i find an object that contains a duplicate key i rollback the transaction and don't store any object in the database (mongodb)

Here my function to store object in the database:


javax.transaction.TransactionManager tx = com.arjuna.ats.jta.TransactionManager.transactionManager();
ArrayList<MesureparamNo> listNoSQL = new ArrayList<MesureparamNo>();
tx.begin() ;
MesureparamNo mes = new MesureparamNo();
for(i=1;i<10000;i++)
{
MesureparamNo mesure = new MesureparamNo();
listNoSQL.add(mesure);
}
for (Iterator<MesureparamNo> itt = listNoSQL.iterator(); itt.hasNext();) {
MesureparamNo enquiry = itt.next();
try{
HibernateUtilNoSQL.getEntityManager().joinTransaction();
HibernateUtilNoSQL.getEntityManager().persist(enquiry);

}catch(Exception re){
tx.rollback();
throw re;
}

}
try{
tx.commit();
}
catch(Exception re){
tx.rollback();
throw re;
}


Top
 Profile  
 
 Post subject: Re: How to rollback a list of object in a transaction
PostPosted: Tue Jan 13, 2015 1:19 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Hi,

Because MongoDB itself does not support transaction, what you are asking is not likely to be doable (for MongoDB at least). Some have explored compensation based transactions for document stores but that is still early stage and a bit ad hoc.

What we plan to have is an error report API that would tell you which inserts have worked and which have not. Based on that, you will be able to manually decide to undo the inserts for example. The issue targeting that feature is https://hibernate.atlassian.net/browse/OGM-465

_________________
Emmanuel


Top
 Profile  
 
 Post subject: Re: How to rollback a list of object in a transaction
PostPosted: Thu Jan 15, 2015 12:14 pm 
Newbie

Joined: Thu May 01, 2014 9:14 pm
Posts: 12
Thanks Emanuel for your answer.
I test the same code with a database SQL(PostgreSQL) which support the transaction using hibernate, i find the same problem of persisting data.So, i think that the problem is not only for Mongodb(NoSQL).
So my question is if my solution is doable with SQL database.if yes which database can support my solution SQL or NoSQL?
thanks


Top
 Profile  
 
 Post subject: Re: How to rollback a list of object in a transaction
PostPosted: Thu Jan 15, 2015 12:34 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Yes that should definitely work.
The next best guess is that the persistence.xml is misconfigured and that the transaction manager and Hibernate are not linked together. So your tx would be rollbacked but contain nothing in the first place whereas the persist would be out of tx and thus committed right away.
Or it could be something in your framework (HibernateUtilNoSQL or test framework).

_________________
Emmanuel


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 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.