[英]OrientDB: can't select data from connected document
I'm trying to execute a simple sql query to retrieve data from the document searched as well as few properties of a connected document. 我正在尝试执行一个简单的SQL查询来从搜索的文档中检索数据以及连接文档的一些属性。 But, for some reason ran into a dead wall on how to select the property from the connected document.
但是,由于某种原因,如何从连接文档中选择属性陷入了困境。 Here is my simple scenario:
这是我的简单场景:
I have 2 documents, an Account and a User. 我有2个文件,一个帐户和一个用户。 Account document has an edge to a User named 'Employs'.
帐户文档对名为“Employs”的用户具有优势。 I'm trying to login a user by email and password.
我正在尝试通过电子邮件和密码登录用户。 If record for the user is found, I simply need to get some user data and few properties from an account document to be stored in user's session.
如果找到用户的记录,我只需要从帐户文档中获取一些用户数据和少量属性,以存储在用户的会话中。
Here is my query: 这是我的查询:
try (ODatabaseDocumentTx db = DbPool.getConnection()) {
String sql
= " select @rid.asString() as userRid, firstName, lastName, "
+ " active as userActive, in('Employs') as account "
+ "from User "
+ "where email = ? and password = ?";
OSQLSynchQuery<ODocument> query = new OSQLSynchQuery<>(sql);
List<ODocument> result = db.command(query).execute('test@test.com', 'abc');
ODocument d = result.get(0);
System.out.println("1 "+ d.field("account.id"));
System.out.println("2 "+ d.field("userRid"));
System.out.println("3 "+ d.field("account.company"));
System.out.println("4 "+ d.field("firstName"));
System.out.println("5 "+ d.field("lastName"));
System.out.println("6 "+ d.field("account.active"));
System.out.println("7 "+ d.field("userActive"));
return new SessionUser(
d.field("account.id"),
d.field("userRid"),
d.field("account.company"),
d.field("firstName"),
d.field("lastName"),
d.field("account.active"),
d.field("userActive"));
}
It fails to create the SessionUser object. 它无法创建SessionUser对象。 More specifically, it fails on retrieval of the account properties.
更具体地说,它无法检索帐户属性。 Here is how the data looks in System.out:
以下是System.out中数据的外观:
1 [17]
2 #37:0
3 [Seller 1]
4 Mike
5 Maloney
6 [true]
7 true
WARN : 2016-11-21 17:53:53,036 WARN c.t.e.k.c.ExceptionHandler - Error: java.util.LinkedHashSet cannot be cast to java.lang.Integer
Here is how a single account.id property looks like in the debugger 以下是调试器中单个account.id属性的外观
I do see that the account properties are coming in as objects, just can't figure out how to select them easy. 我确实看到帐户属性作为对象进入,只是无法弄清楚如何轻松选择它们。 I didn't want to go through manually casting list then set, etc. to get to a simple account.id element.
我不想通过手动转换列表然后设置等来获得一个简单的account.id元素。 I'm sure there is a straight forward way, just can't see it.
我确信有一种直截了当的方式,就是看不到它。
What is the right way to select data of a connected document? 选择连接文档数据的正确方法是什么? Or, is there a better way to construct the query itself?
或者,有没有更好的方法来构建查询本身?
Thanks. 谢谢。
我已在Google网上论坛上回复了您https://groups.google.com/d/msg/orient-database/ta4izTYq-CY/l5tHPOu5CgAJ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.