Converting a SQL result to a POJO - Question

198 views
Skip to first unread message

kabustalek

unread,
Apr 11, 2012, 6:46:31 AM4/11/12
to orient-...@googlegroups.com
Hi,

i have a query like
List<ODocument>  result = db.command(new OSQLSynchQuery<ODocument>("select from index:unprocessed where key = [false,false]", 1)).execute();

When i execute this, i get an ArrayList with size of 95 - but i thought the 1 should limit the result to 1 - i think this would increase performance.
The next question is, how can i transfer this ODocument to my POJO?
When i try it with
ORID identity = ((ODocument)db.getUserObjectByRecord(result.get(0), null)).getIdentity();
POJO pojo = (POJO) db.load(identity);

i get the exception:
java.lang.IllegalArgumentException: Cannot create the object: class name is empty
    at com.orientechnologies.orient.core.entity.OEntityManager.createPojo(OEntityManager.java:59)
    at com.orientechnologies.orient.core.db.object.ODatabaseObjectTx.newInstance(ODatabaseObjectTx.java:85)
    at com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:361)
    at com.orientechnologies.orient.core.db.ODatabasePojoAbstract.getUserObjectByRecord(ODatabasePojoAbstract.java:339)

Any ideas? Is there a better way to get my pojo?

kabustalek

unread,
Apr 11, 2012, 8:55:04 AM4/11/12
to orient-...@googlegroups.com
got it fixed with
ODocument tmp = result.get(0).field("rid");
db.getUserObjectByRecord(tmp, null);

But the sql is not working as supposed - it returns all entrys. even those where key = true, true
The limit 1 looks like beeing ignored.

Salvatore Piccione

unread,
Apr 11, 2012, 9:01:24 AM4/11/12
to orient-...@googlegroups.com
Hello,

the SQL LIMIT issue has been recently discussed in this ML (http://groups.google.com/group/orient-database/browse_thread/thread/6e9b9e1df5c5b091/4110d6b1017cbbe8?#4110d6b1017cbbe8). According to Luca's post at http://groups.google.com/group/orient-database/msg/4110d6b1017cbbe8, try to set the LIMIT in the SQL Query and not to pass it as parameter to the SQL object:
"select from index:unprocessed where key = [false,false] LIMIT 1"

HTH,

Salvatore

2012/4/11 kabustalek <oliver...@googlemail.com>

Luca Molino

unread,
Apr 11, 2012, 9:02:05 AM4/11/12
to orient-...@googlegroups.com
Hi,

the query limit should be set in the query text, the limit parameter is an old implementation mantained for compatibility reasons.

List<ODocument>  result = db.command(new OSQLSynchQuery<ODocument>("select from index:unprocessed where key = [false,false] limit 1")).execute();

Luca Molino

kabustalek

unread,
Apr 11, 2012, 9:18:44 AM4/11/12
to orient-...@googlegroups.com
thanks for your response. But i still retrieve the whole list and also the index is somehow ignored when i put it in the sql query. I fear my sql is wrong. The pojo on the first position has it fields processing and processed set to true/true, so it should not be listed, shouldnt it?

Luca Molino

unread,
May 4, 2012, 12:34:22 PM5/4/12
to orient-...@googlegroups.com
Hi,

since we added a new Object Database implementation can you test it with the latest trunk and changing ODatabaseObject with OObjectDatabase?

2012/4/11 kabustalek <oliver...@googlemail.com>
Reply all
Reply to author
Forward
0 new messages