Returning two node entities in one Cypher query through SDN

471 views
Skip to first unread message

Abdul Azeez Shaik

unread,
Oct 8, 2012, 11:41:00 PM10/8/12
to ne...@googlegroups.com
Hi,

Can i return two node entities through cypher query in SDN?
for ex:

@Query( "START n=node:search({0}) RETURN n")

Iterable<User> doBasicSearch(String query);


Apart from Iterable of one Node Entity, can i give a object which has User and Product?
like this,
Class Result {
Iterable<User> users;
Iterable<Product> products;
}

Result doBasicSearch(String query);

Kindly let me know on how to achieve this through Spring Data Neo4j. 
These are versions i have included in pom,
     <spring-data-neo4j.version>2.1.0.RC4</spring-data-neo4j.version>
     <org.jackson-version>1.9.7</org.jackson-version>
<neo4j.version>1.8.RC1</neo4j.version>

Thanks,
Abdul

Michael Hunger

unread,
Oct 9, 2012, 2:02:44 AM10/9/12
to ne...@googlegroups.com
You mean two different node-entities?
What is your use-case?

You can actually project the entities.

it should be also possible to use

@MapResult
interface Result {
   @ResultColumn("n") Iterable<User> getAsUsers();
   @ResultColumn("n") Iterable<Product> getAsProducts();
}

please try that.

--
 
 

Abdul Azeez Shaik

unread,
Oct 10, 2012, 12:41:39 PM10/10/12
to ne...@googlegroups.com
This one looks great!
However, there is no mention of this in spring-data-neo4j documentation except in one example of 17.1.
This would drag more attention, If this could be part of "Reference Documentation" part.

Thanks for providing me this option.

Regards,
 Abdul

--
 
 

Michael Hunger

unread,
Oct 10, 2012, 1:00:06 PM10/10/12
to ne...@googlegroups.com
B/c this is a corner case :)
Projection in general is mentioned and promoted.

Michael

--
 
 

Abdul Azeez Shaik

unread,
Oct 13, 2012, 5:30:13 AM10/13/12
to ne...@googlegroups.com
Hi Michael,

Apart from @MapResult, there is other form of Return type Iterable<Map<String,Object>>

1.Can i use this return type to return one column and one entity? 

For ex: Query("START n=node:username(username= {0}) MATCH n-[]-user RETURN n.name, user"). Can i use Iterable<Map<String, Object>> for above query. Or do i need to use @MapResult even for this?

2. In Neo4j(.i.e.without using SDN), Map is results of column names with the respective data. But, in case of SDN, they will be directly associated to @NodeEntity, so what could be the use cases where we can use Iterable<Map<String, Object>>.

Kindly help me in understanding above result types.

Thanks,
Abdul

On Tue, Oct 9, 2012 at 11:32 AM, Michael Hunger <michael...@neotechnology.com> wrote:
--
 
 

Michael Hunger

unread,
Oct 13, 2012, 6:28:53 AM10/13/12
to ne...@googlegroups.com


Sent from mobile device

Am 13.10.2012 um 11:30 schrieb Abdul Azeez Shaik <azeezte...@gmail.com>:

Hi Michael,

Apart from @MapResult, there is other form of Return type Iterable<Map<String,Object>>

1.Can i use this return type to return one column and one entity? 


Yes

For ex: Query("START n=node:username(username= {0}) MATCH n-[]-user RETURN n.name, user"). Can i use Iterable<Map<String, Object>> for above query. Or do i need to use @MapResult even for this?

No mapresult is just a thin wrapper around this for convenience


2. In Neo4j(.i.e.without using SDN), Map is results of column names with the respective data. But, in case of SDN, they will be directly associated to @NodeEntity, so what could be the use cases where we can use Iterable<Map<String, Object>>.

Here each map reprents a row mappin the column name to the object.

--
 
 

Abdul Azeez Shaik

unread,
Oct 13, 2012, 8:43:27 AM10/13/12
to ne...@googlegroups.com
Hi Michael,

I just tried following query ("START n=node:username(username= {0}) MATCH n-[]-user RETURN n.name, user") with Result type as Iterable<Map<String, User>>.

User is NodeEntity in my code.

However, instead of returning USER object, it returned org.neo4j.rest.graphdb.entity.RestNode type. Can you please let me know if i need to add anything specific here.

Before this, i just had Iterable<User> which use to work fine.

Kindly let me know your opinion on this.

Thanks,
Abdul

--
 
 

Michael Hunger

unread,
Oct 13, 2012, 9:33:30 AM10/13/12
to ne...@googlegroups.com
Ok I probably incorrectly assumed that the nodes would be converted in this case.

So it seems you have to use MapResult anyway.



Sent from mobile device
--
 
 
Reply all
Reply to author
Forward
0 new messages