Only it has failed once, but not identified the cause.
* I assume that you start the transaction for each session before you being using them?
Only use these 2 sessions, and only call sessionsFact.openSession() before find objects to process. start the transaction? it does not start hibernate?
and only flush and commit after processing (at end of main()).
The process:
Code:
// find in bbdd1
iter1 = sessionSource.find(...).iterator();
while (iter1.hasNext())
{
// Process obj
Syslog currentObj = (Syslog)iter1.next()
process(currentObj); //set attributes
findOtherObjectAndUpdateIt(sessionDest, currentObj);
sessionDest.save(currentObj);
}
sessionDest.flush();
sessionDest.connection().commit();
the method2 findOtherObjectAndUpdateIt(sessionDest, obj) search another object in sessionDest (bbdd2):
Code:
findOtherObjectAndUpdateIt (sessionDest, currentObj)
{
...
Query q = session.createQuery(...);
q.setParameter("xxx", currentObj.getXXX());
q.setParameter("yyy", currentObj.getYYY());
list2 = q.list() // HERE throws the exception
iter2 = list2.iterator();
while (iter2.hasNext())
{
// Process otherObject to set attributes required in bbdd2
Syslog otherObject = (Syslog)iter2.next();
otherObject.setXXX(...);
}
}
the
otherObject that i want to update can be of that I have processed in iter1 (a previous currentObj) or that already was in bbdd2 (not find in this iter1 bbdd1).
I don't know if the problem is transactions, or if the otherObject is one of previously process (found in bbdd1) and still has not been flush and commit or what?
Thanks again for all,
Cesar.
PD: You excuse my terrible english.