orientdb icon indicating copy to clipboard operation
orientdb copied to clipboard

Object DB / SQL: Using POJO as parameter causes ClassCastException

Open dxxr opened this issue 12 years ago • 1 comments

OrientDB v.1.7-rc2

Let's assume two model POJOs Group and Item where each Group holds a List of Items and an Item can belong to many Groups. Now when an Item gets deleted, it has to be removed from all Groups referencing it:

String cmd = "UPDATE Group REMOVE items = :item";
Map param = new HashMap<>();
param.put("item", itemProxy); // the item's db proxy object

OObjectDatabaseTx db = pool.acquire();
db.command(new OCommandSQL(cmd)).execute(param);

Stepping through I've noticed that the OCommandSQLPojoWrapper converts the given POJO proxy parameter to it's associated ORecordId.

But when the query is executed, I still receive the following Exception:

com.orientechnologies.orient.core.exception.OCommandExecutionException: Error on execution of command: sql.select from Group
    at com.orientechnologies.orient.core.storage.OStorageEmbedded.executeCommand(OStorageEmbedded.java:102)
    at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OStorageEmbedded.java:85)
    at com.orientechnologies.orient.core.sql.query.OSQLQuery.run(OSQLQuery.java:69)
    at com.orientechnologies.orient.core.query.OQueryAbstract.execute(OQueryAbstract.java:29)
    at com.orientechnologies.orient.core.db.record.ODatabaseRecordAbstract.query(ODatabaseRecordAbstract.java:692)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.execute(OCommandExecutorSQLUpdate.java:201)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:57)
    at com.orientechnologies.orient.core.storage.OStorageEmbedded.executeCommand(OStorageEmbedded.java:96)
    at com.orientechnologies.orient.core.storage.OStorageEmbedded.command(OStorageEmbedded.java:85)
    at com.orientechnologies.orient.core.command.OCommandRequestTextAbstract.execute(OCommandRequestTextAbstract.java:59)
    at com.orientechnologies.orient.object.db.OCommandSQLPojoWrapper.execute(OCommandSQLPojoWrapper.java:46)
...
Caused by: java.lang.ClassCastException: com.orientechnologies.orient.core.sql.filter.OSQLFilterItemField cannot be cast to com.orientechnologies.orient.core.db.record.OIdentifiable
    at com.orientechnologies.orient.core.db.record.ORecordLazyList.remove(ORecordLazyList.java:230)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLUpdate.result(OCommandExecutorSQLUpdate.java:390)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.addResult(OCommandExecutorSQLSelect.java:682)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.handleResult(OCommandExecutorSQLSelect.java:624)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearchRecord(OCommandExecutorSQLSelect.java:595)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.executeSearch(OCommandExecutorSQLSelect.java:543)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLSelect.execute(OCommandExecutorSQLSelect.java:495)
    at com.orientechnologies.orient.core.sql.OCommandExecutorSQLDelegate.execute(OCommandExecutorSQLDelegate.java:57)
    at com.orientechnologies.orient.core.storage.OStorageEmbedded.executeCommand(OStorageEmbedded.java:96)
    ... 47 more

dxxr avatar Apr 14 '14 17:04 dxxr

Hi,

This should be already fixed in 3.x

Regards

tglman avatar Jan 02 '18 13:01 tglman