StevenTomer
unread,May 22, 2012, 2:27:57 PM5/22/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Sign in to report message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to OrientDB
Hello,
If a record with a unique key in a transaction is deleted, and a new
record with the same key in the same transaction is created, an
OIndexException can be thrown, dependent on the order of the two
operations.
It seems logical to think of a transaction as a single functional
unit. When building the transaction, It doesn't seem like good
practice to force the calling code to order create/update/delete
operations explicitly.
This problem also happens when using the remote NetworkBinaryProtocol
interface.
Steve
Test case below:
// SETUP DB
final String url = "remote:localhost/testorient";
try {
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url);
System.out.println("Recreating database");
if (ODatabaseHelper.existsDatabase(db)) {
db.setProperty("security", Boolean.FALSE);
ODatabaseHelper.dropDatabase(db, url);
}
ODatabaseHelper.createDatabase(db, url);
db.close();
}
catch (IOException ex) {
System.out.println("Exception: " + ex);
}
// OPEN DB, Create Schema
ODatabaseDocumentTx db = new ODatabaseDocumentTx(url).open("admin",
"admin");
OClass personClass =
db.getMetadata().getSchema().createClass("Person");
personClass.createProperty("name",
OType.STRING).createIndex(OClass.INDEX_TYPE.UNIQUE);
personClass.createProperty("identifier",
OType.STRING).createIndex(OClass.INDEX_TYPE.NOTUNIQUE);
db.getMetadata().getSchema().save();
// CREATE RECORDS
db.begin();
ODocument a = new ODocument("Person").field("name",
"A").field("identifier", "A");
ODocument b = new ODocument("Person").field("name",
"B").field("identifier", "B");
ODocument c = new ODocument("Person").field("name",
"C").field("identifier", "C");
ODocument d = new ODocument("Person").field("name",
"D").field("identifier", "D");
a.save();
b.save();
c.save();
d.save();
db.commit();
// DELETE BEFORE SAVE
System.out.println("DELETE BEFORE SAVE");
db.begin();
db.delete(b);
ODocument b2 = new ODocument("Person").field("name",
"B").field("identifier", "B2");
b2.save();
db.commit();
// SAVE BEFORE DELETE - this throws an exception!
System.out.println("SAVE BEFORE DELETE");
db.begin();
ODocument a2 = new ODocument("Person").field("name",
"A").field("identifier", "A2");
a2.save();
db.delete(a);
db.commit();
System.out.println("END");
db.close();
The above gives the message:
Exception in thread "main"
com.orientechnologies.orient.core.index.OIndexException: Found
duplicated key 'A' in index 'Person.name' previously assigned to the
record #6:0
at
sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at
sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:
57)
at
sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:
45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:
525)
at
com.orientechnologies.orient.enterprise.channel.binary.OChannelBinary.createException(OChannelBinary.java:
411)
at
com.orientechnologies.orient.enterprise.channel.binary.OChannelBinary.handleStatus(OChannelBinary.java:
364)
at
com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryAsynch.beginResponse(OChannelBinaryAsynch.java:
145)
at
com.orientechnologies.orient.enterprise.channel.binary.OChannelBinaryAsynch.beginResponse(OChannelBinaryAsynch.java:
60)
at
com.orientechnologies.orient.client.remote.OStorageRemote.beginResponse(OStorageRemote.java:
1486)
at
com.orientechnologies.orient.client.remote.OStorageRemote.commit(OStorageRemote.java:
820)
at
com.orientechnologies.orient.client.remote.OStorageRemoteThread.commit(OStorageRemoteThread.java:
196)
at
com.orientechnologies.orient.core.tx.OTransactionOptimistic.commit(OTransactionOptimistic.java:
58)
at
com.orientechnologies.orient.core.db.record.ODatabaseRecordTx.commit(ODatabaseRecordTx.java:
112)
at
com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.commit(ODatabaseDocumentTx.java:
313)
at TestApp.main(TestApp.java:104)