Hi,
My Hibernate App includes functionality to "synchronize" data between two databases (one for development and production). I'm trying to use Hibernate to copy/update data, but I'm crashing again and again. Should I use plain SQL to INSERT / UPDATE data on my production DB?
All my objects have to use "assigned" for generator class, because when I'm copying the objects I need to retain the actual object ID (for future updates), so the object has an ID and should be INSERTed on the production database.
I think I should use something like that:
Code:
Session devSess = getDevelopmentSession();
Session productionSession = getProductionSession();
Iterator it = devSess.createQuery ("the query").iterat();
while (it.hasNext()) {
MyObject obj = it.next();
devSess.evict (obj);
if (isExistingObject (productionSession)) {
productionSession.save (obj);
}
else {
productionSession.update (obj);
}
}
If it's a new object, everything go OK, ** but **, when the object exists on the production DB, the code fails with "NonUniqueObjectException".
I think that, since I'm calling "update()" (and not save()), the object indeed exists!!! What I'm missing??
I've tried everything: saveOrUpdateCopy(), replicate(), creating a new transient object using a "copy constructor"... allways the same NonUniqueObjectException.
Any ideas? Is there a method (a mean a way) to do this? Should I implement an Interceptor? A Persister?? Should I use plain SQL or other "data base specific tools"?
I'm using Hibernate 2.1.3. My development database is an Oracle 8.1.7, and my production database is an Oracle 9i
Thanks in advance for any kind of help,
Gustavo Comba