Newbie question

157 views
Skip to first unread message

Ricardo Borillo

unread,
Jan 30, 2013, 12:02:25 PM1/30/13
to neo4j...@googlegroups.com
Hi all,

Thanks for such an interesting work!!!
I'm just trying to create some cypher queries with neo4j-scala API but i always get and UnsupportedOperation exception.

I'm using the following version of neo4j-scala:

"org.neo4j" % "neo4j-scala" % "0.2.0-M2-SNAPSHOT"

My data case class is:

case class Author(name: String, typeName: String)

And my repository class:

object AuthorsRepository extends Neo4jWrapper with RestGraphDatabaseServiceProvider with Cypher {

  def uri = new URI("http://localhost:7474/db/data/")

  ShutdownHookThread {
    shutdown(ds)
  }

  def authors: List[Author] = {
    val query = "start n=node(*) where n.typeName = \"AUTHOR\" return n"
    query.execute.asCC[Author]("n").toList
  }

  def add(author: Author) {
    withTx {
      implicit neo =>
        val start = createNode
        start("name") = author.name
        start("typeName") = "AUTHOR"
    }
  }
}

I'm following the example published at GitHub:


Any clues for a newbie? :P

Best regards,
  Ricardo

Ricardo Borillo

unread,
Jan 30, 2013, 12:18:47 PM1/30/13
to neo4j...@googlegroups.com
In the neo-shell, this simple query works without problems ...

neo4j-sh (?)$ start n=node(*) return n;
+---------------------------------------------+
| n                                           |
+---------------------------------------------+
| Node[4]{name:"Bob Dylan",typeName:"AUTHOR"} |
+---------------------------------------------+
1 row
1 ms

Ricardo Borillo

unread,
Jan 30, 2013, 12:22:08 PM1/30/13
to neo4j...@googlegroups.com
A more simple approach without case clase type conversion also fails with the same error:

val query = "start n=node(*) return n"
println(engine.execute(query).dumpToString())

Christopher Schmidt

unread,
Jan 31, 2013, 11:32:44 AM1/31/13
to Ricardo Borillo, neo4j...@googlegroups.com

That is because every next is validated against its type. The type (as Java class name) is stored in a "_CLASS_" property of the node. If it does not fit to the given type (using is assignablefrom) , null is returned.

If you want to exclude the null results append ".filter(_ != null)" to toList or add the class property to the Cypher query.

This is not very convenient but should work.

Best Christopher

Am 31.01.2013 13:04 schrieb "Ricardo Borillo" <bor...@gmail.com>:
Hi Chistopher,

The collection seems to be fulled with the item, but i'm not able to
find a way to recover the queried item.
This should work:

    "be able to execute (*) query" in {

      val query = """start n=node(*) where n.name?="Neo" return n"""

      val typedResult = query.execute.asCC[Test_Matrix]("n")
      typedResult.toList.size must be_>(0)
      typedResult.hasNext must beTrue
      typedResult.next must not beNull

      success
    }

hasNext assertion passes, but next returns null and the test fails.
What i'm doing wrong?

Thanks a lot for your help :)

---
Salut,
====================================
Ricardo Borillo Domenech
http://xml-utils.com / http://twitter.com/borillo


On Thu, Jan 31, 2013 at 11:54 AM, Christopher Schmidt
<fako...@gmail.com> wrote:
> I've added an additional test case, which works for me (although the 1st
> result is null). See
> https://github.com/FaKod/neo4j-scala/commit/0e46de14897dcc5ad19419bfc017375e05d6e286
>
> Can you play around with this testcase a little by executing mvn install?
>
>
> On Thu, Jan 31, 2013 at 7:26 AM, Ricardo Borillo <bor...@gmail.com> wrote:
>>
>> Hi,
>>
>> Yes i do, but the example is not working when you specify * instead of an
>> existing I'd reference .... * value works fine in the shell but it doesn't
>> work through the API :/
>>
>> Best regards,
>>   Ricardo
>>
>> El 31/01/2013, a las 06:23, Christopher Schmidt <fako...@gmail.com>
>> escribió:
>>
>> Have you had a look at:
>> https://github.com/FaKod/neo4j-scala/blob/0.2.0-M/src/test/scala/org/neo4j/scala/unittest/CypherTest.scala
>>
>> The test works fine for me. The neo4j-scala Cypher implementation is more
>> or less a direct delegation to the Java one.
>>
>> best Christopher
>>
>> On Wed, Jan 30, 2013 at 6:47 PM, Ricardo Borillo <bor...@gmail.com>
>> wrote:
>>>
>>> Hi,
>>>
>>> Ok. Now is not crashing using
>>> SingletonEmbeddedGraphDatabaseServiceProvider, but the mapping with
>>> the case clase is not working.
>>> The result now is List(null) :'(
>>>
>>> Thanks for your help :)
>>> ---
>>> Salut,
>>> ====================================
>>> Ricardo Borillo Domenech
>>> http://xml-utils.com / http://twitter.com/borillo
>>>
>>>
>>> On Wed, Jan 30, 2013 at 6:30 PM, Christopher Schmidt <fako...@gmail.com>
>>> wrote:
>>> > That's because you are using the REST provider (should work with the
>>> > local
>>> > one).
>>> >
>>> > I will try to have a look at it tomorrow.
>>> >
>>> > Christopher
>>> >> --
>>> >> You received this message because you are subscribed to the Google
>>> >> Groups
>>> >> "neo4j-scala" group.
>>> >> To unsubscribe from this group and stop receiving emails from it, send
>>> >> an
>>> >> email to neo4j-scala...@googlegroups.com.
>>> >> To post to this group, send email to neo4j...@googlegroups.com.
>>> >> For more options, visit https://groups.google.com/groups/opt_out.
>>> >>
>>> >>
>>
>>
>

Ricardo Borillo

unread,
Feb 4, 2013, 4:03:55 AM2/4/13
to Christopher Schmidt, neo4j...@googlegroups.com
Hi Cristopher,

Thanks for your help. Now is working fine :)

Best regards
---
Salut,
====================================
Ricardo Borillo Domenech
http://xml-utils.com / http://twitter.com/borillo


Reply all
Reply to author
Forward
0 new messages