How to connect my JRuby shell to Neo4J?

82 views
Skip to first unread message

mulder.patrick

unread,
Apr 29, 2013, 11:02:10 AM4/29/13
to neo...@googlegroups.com
Sorry if I cross posted this on SO too, but I just see this dedicated email list to Neo4J.rb, so, maybe i makes sense to ask my question here too:

I would like to experiment with some data from within my Ruby console, and eventually using Cypher from a Ruby console too. As I like the Neo4J server I got on a USB stick, I tried to start my Neo4J server with:

/Users/mulder/neo4j-community-1.9.RC1
→ bin/neo4j start
WARNING! You are using an unsupported version of the Java runtime. Please use Oracle(R) Java(TM) Runtime Environment 7.
Starting Neo4j Server...WARNING: not changing user
process [14423]... waiting for server to be ready.... OK.
Go to http://localhost:7474/webadmin/ for administration interface.

That looks successful. But now, after I installed the Neo4J Ruby gem and load it into the shell, I get stuck. I wanted to do a simple test of my connection with:

irb(main):005:0> n = Neo4j::Node.new
I, [2013-04-29T16:30:34.919000 #15019]  INFO -- : Starting local Neo4j using db /Users/mulder/neo4j-community-1.9.RC1/db using Java::OrgNeo4jKernel::EmbeddedGraphDatabase
NativeException: org.neo4j.graphdb.NotInTransactionException: null
    from org/neo4j/kernel/impl/persistence/PersistenceManager.java:252:in `getResource'
    from org/neo4j/kernel/impl/persistence/PersistenceManager.java:155:in `nodeCreate'
    from org/neo4j/kernel/impl/core/NodeManager.java:195:in `createNode'
    from org/neo4j/kernel/InternalAbstractGraphDatabase.java:850:in `createNode'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/gems/1.8/gems/neo4j-core-2.2.3-java/lib/neo4j-core/node/class_methods.rb:32:in `new'
    from (irb):5:in `evaluate'
    from org/jruby/RubyKernel.java:1083:in `eval'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/1.8/irb.rb:158:in `eval_input'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/1.8/irb.rb:271:in `signal_status'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/1.8/irb.rb:155:in `eval_input'
    from org/jruby/RubyKernel.java:1410:in `loop'
    from org/jruby/RubyKernel.java:1183:in `catch'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/1.8/irb.rb:154:in `eval_input'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/1.8/irb.rb:71:in `start'
    from org/jruby/RubyKernel.java:1183:in `catch'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/lib/ruby/1.8/irb.rb:70:in `start'
    from /Users/mulder/.rbenv/versions/jruby-1.6.7/bin/irb:13:in `(root)'irb(main)

Any idea, what I might miss?

Thank you very much for your feedback!

Andreas Ronge

unread,
Apr 29, 2013, 11:13:07 AM4/29/13
to neo...@googlegroups.com
Hi

The NotInTransactionException is because you missed creating a transaction. E.g. Neo4j::Transaction.run { Neo4j::Node.new }
or use the Neo4j Active Model layer:
class Person < Neo4j::Rails::Model end
Person.create

If you want to use the Neo4j Server together with the embedded neo4j database you must use HA, https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3Aha-cluster

Notice, you don't need the Neo4j Server when using neo4j.rb.




--
You received this message because you are subscribed to the Google Groups "neo4jrb" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4jrb+u...@googlegroups.com.
To post to this group, send email to neo...@googlegroups.com.
Visit this group at http://groups.google.com/group/neo4jrb?hl=en.

For more options, visit https://groups.google.com/groups/opt_out.
 
 

mulder.patrick

unread,
Apr 29, 2013, 4:20:15 PM4/29/13
to neo...@googlegroups.com


On Monday, April 29, 2013 5:13:07 PM UTC+2, ronge wrote:
Hi

The NotInTransactionException is because you missed creating a transaction. E.g. Neo4j::Transaction.run { Neo4j::Node.new }
or use the Neo4j Active Model layer:
class Person < Neo4j::Rails::Model end
Person.create

If you want to use the Neo4j Server together with the embedded neo4j database you must use HA, https://github.com/andreasronge/neo4j/wiki/Neo4j%3A%3Aha-cluster

Notice, you don't need the Neo4j Server when using neo4j.rb.



Hm.. the background is that I want to import some data with a Ruby script to explore some Cypher queries, without actually needing the web application right now. But you are right, the ActiveModel approach looks working easily:

irb(main):010:0> Person.create
Starting local Neo4j using db /Users/pmu/neo4j-community-1.9.RC1/ruby_tests/db using Java::OrgNeo4jKernel::EmbeddedGraphDatabase
=> #<Person:0x617df472 @errors=#<ActiveModel::Errors:0x143b9a5f @base=#<Person:0x617df472 ...>, @messages=#<OrderedHash {}>>, @_relationships={}, @_properties={"_classname"=>"Person"}, @changed_attributes={}, @_create_or_updating=nil, @_java_node=#<Java::OrgNeo4jKernelImplCore::NodeProxy:0x498b5a73>, @previously_changed={"_classname"=>["Person", "Person"]}, @_properties_before_type_cast={}, @validation_context=nil>


However, if I want to access the API with the Ruby shell I first got:

irb(main):011:0> Neo4j::Transaction.run { @node = Neo4j::Node.new }
NativeException: org.neo4j.kernel.impl.persistence.ResourceAcquisitionFailedException: The transaction is marked for rollback only.
from org/neo4j/kernel/impl/persistence/PersistenceManager.java:275:in `getResource'
from org/neo4j/kernel/impl/persistence/PersistenceManager.java:155:in `nodeCreate'
from org/neo4j/kernel/impl/core/NodeManager.java:195:in `createNode'
from org/neo4j/kernel/InternalAbstractGraphDatabase.java:850:in `createNode'
from /Users/pmu/.rbenv/versions/jruby-1.6.8/lib/ruby/gems/1.8/gems/neo4j-core-2.2.3-java/lib/neo4j-core/node/class_methods.rb:32:in `new'
from (irb):11:in `evaluate'
from /Users/pmu/.rbenv/versions/jruby-1.6.8/lib/ruby/gems/1.8/gems/neo4j-core-2.2.3-java/lib/neo4j/transaction.rb:71:in `run'
from (irb):11:in `evaluate'
from org/jruby/RubyKernel.java:1112:in `eval'
from /Users/pmu/.rbenv/versions/jruby-1.6.8/lib/ruby/1.8/irb.rb:158:in `eval_input'


After loading the rails gem, I got:

irb(main):013:0>  Neo4j::Transaction.run { @neo = Neo4j::Node.new }
=> #<Java::OrgNeo4jKernelImplCore::NodeProxy:0x5cca548b>

But so far, I don't see any new nodes when going to the http://localhost:7474 webadmin.

Not sure, if/how I am mixing up the API/embedded/HA contexts.


Andreas Ronge

unread,
Apr 30, 2013, 5:52:28 AM4/30/13
to neo...@googlegroups.com
Hi

Make sure that you are not running the Neo4j Server at the same time as running Neo4j Embedded (neo4j.rb) unless you are using HA.
There could be problems if the Neo4j Server and Neo4j.rb does not use the same Neo4j Java libraries. I guess you are using Neo4j 1.8.1 libraries if you uses the
latest neo4j.rb release 2.2.3 (unless you have tweeked your Gemfile). Try using the Neo4j 1.8.1 Server and run your ruby script and exit ruby and then start the Neo4j server.

Cheers


Reply all
Reply to author
Forward
0 new messages