Details
Description
I need to delete all in a DB related to a pk and then insert new data with the
same pk inside the same transaction. Even if Oracle supports this feature,
Castor don't let me do it. I read JDO FAQ at Castor's website and I found that:
"Can an object with the same identity be re-created after being removed in the
same transaction?
Yes, as long as the deleted object is the same instance as the one being recreated."
So, I try to do this and did not work. Here is the test-code that I've used:
public class Job_XF {
public static void execute( java.util.Hashtable variables ) {
try {
JDO jdo = new JDO("fomentola");
jdo.loadConfiguration(
(Job_XF.class).getResource("/connection.xml").toString() );
Database db = jdo.getDatabase();
db.begin();
co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol
rhF =
(co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol)db.load(
co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol.class, new
Complex( new Object[]
) );
db.remove(rhF);
db.create(rhF);
db.commit();
db.close();
} catch(Exception e)
{ e.printStackTrace(); } }
}
After execution this is the Exception stack:
org.exolab.castor.jdo.DuplicateIdentityException: Duplicate identity found for
object of type
co.gov.colciencias.interscienti.fomentola.En_producao_cientif_tecnol with
identity <29918(927458),0000283878(1484588876)>: an object with the same
identity already exists in persistent storage
at org.exolab.castor.persist.LockEngine.create(LockEngine.java:469)
at
org.exolab.castor.persist.TransactionContext.create(TransactionContext.java:941)
at org.exolab.castor.jdo.engine.DatabaseImpl.create(DatabaseImpl.java:380)
at config.projects.cvlac.scripts.Job_XF.execute(Job_XF.java:19)
at
config.projects.cvlac.scripts.Job_CanBeDeleted.main(Job_CanBeDeleted.java:29)
Does it really have to be within the same transaction ?