JRuby

Cannot get Jruby to work with Neo4j

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1
  • Fix Version/s: None
  • Component/s: Java Integration
  • Labels:
    None
  • Environment:
    OSX Leopard
  • Number of attachments :
    1

Description

The network oriented database Neo4j (www.neo4j.org) made med pick up Jruby again. However, it fails badly in Jruby, and I'm unable to make much of the stack trace generated. It seems to originate from somewhere deep within Jruby (org.jruby.javasupport.JavaMethod.invokeWithExceptionHandling, the full trace follows (jruby code included as attachment):

TxManager.java:721:in `org.neo4j.impl.transaction.TxManager.getStatus': java.lang.NullPointerException: null (NativeException)
from UserTransactionImpl.java:91:in `org.neo4j.impl.transaction.UserTransactionImpl.getStatus'
from TransactionUtil.java:66:in `org.neo4j.impl.transaction.TransactionUtil.beginTx'
from Transaction.java:91:in `org.neo4j.api.core.Transaction.begin'
from NativeMethodAccessorImpl.java:-2:in `sun.reflect.NativeMethodAccessorImpl.invoke0'
from NativeMethodAccessorImpl.java:39:in `sun.reflect.NativeMethodAccessorImpl.invoke'
from DelegatingMethodAccessorImpl.java:25:in `sun.reflect.DelegatingMethodAccessorImpl.invoke'
from Method.java:585:in `java.lang.reflect.Method.invoke'
from JavaMethod.java:196:in `org.jruby.javasupport.JavaMethod.invokeWithExceptionHandling'
... 9 levels...
from Main.java:174:in `org.jruby.Main.runInterpreter'
from Main.java:120:in `org.jruby.Main.run'
from Main.java:95:in `org.jruby.Main.main'
Complete Java stackTrace
java.lang.NullPointerException
at org.neo4j.impl.transaction.TxManager.getStatus(TxManager.java:721)
at org.neo4j.impl.transaction.UserTransactionImpl.getStatus(UserTransactionImpl.java:91)
at org.neo4j.impl.transaction.TransactionUtil.beginTx(TransactionUtil.java:66)
at org.neo4j.api.core.Transaction.begin(Transaction.java:91)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.jruby.javasupport.JavaMethod.invokeWithExceptionHandling(JavaMethod.java:196)
at org.jruby.javasupport.JavaMethod.invoke_static(JavaMethod.java:182)
at org.jruby.javasupport.JavaClass$StaticMethodInvoker.execute(JavaClass.java:371)
at org.jruby.internal.runtime.methods.SimpleCallbackMethod.call(SimpleCallbackMethod.java:81)
at org.jruby.RubyObject.compilerCallMethod(RubyObject.java:508)
at org.jruby.javasupport.util.CompilerHelpers.doInvokeDynamic(CompilerHelpers.java:124)
at EVAL5275383._file_(EVAL5275383:6)
at EVAL5275383.run(EVAL5275383)
at org.jruby.Ruby.compileOrFallbackAndRun(Ruby.java:322)
at org.jruby.Main.runInterpreter(Main.java:229)
at org.jruby.Main.runInterpreter(Main.java:174)
at org.jruby.Main.run(Main.java:120)
at org.jruby.Main.main(Main.java:95)

Activity

Hide
Emil Eifrem added a comment -

I don't know the JRuby specifics, but this code seems to work fine:

working_neo4j_test.rb
#!/usr/bin/env ruby

include Java

import org.neo4j.api.core.Node
import org.neo4j.api.core.EmbeddedNeo
import org.neo4j.api.core.Transaction
  
if __FILE__ == $0
  neo = EmbeddedNeo.new('test')
  tx = Transaction.begin
  begin
    n1 = neo.create_node
    n1.set_property('name', "I am a node")
    tx.success
  rescue Exception => e
    puts e.inspect
  ensure
    tx.finish
    neo.shutdown
  end
end

(adapted from http://pastie.caboo.se/193374 which I guess may disappear)

So may it just be that it's lacking a:

neo = org.neo4j.core.api.EmbeddedNeo.new('test')

before the Transaction.begin()?

Unfortunately, I don't have a JRuby environment set up to try it.

Show
Emil Eifrem added a comment - I don't know the JRuby specifics, but this code seems to work fine:
working_neo4j_test.rb
#!/usr/bin/env ruby

include Java

import org.neo4j.api.core.Node
import org.neo4j.api.core.EmbeddedNeo
import org.neo4j.api.core.Transaction
  
if __FILE__ == $0
  neo = EmbeddedNeo.new('test')
  tx = Transaction.begin
  begin
    n1 = neo.create_node
    n1.set_property('name', "I am a node")
    tx.success
  rescue Exception => e
    puts e.inspect
  ensure
    tx.finish
    neo.shutdown
  end
end
(adapted from http://pastie.caboo.se/193374 which I guess may disappear) So may it just be that it's lacking a:
neo = org.neo4j.core.api.EmbeddedNeo.new('test')
before the Transaction.begin()? Unfortunately, I don't have a JRuby environment set up to try it.
Hide
Marius Mathiesen added a comment -

Oh dear, oh dear, my fault completely. Your code works like a charm, this really makes me excited.. Thanks a million!

Show
Marius Mathiesen added a comment - Oh dear, oh dear, my fault completely. Your code works like a charm, this really makes me excited.. Thanks a million!
Hide
Thomas E Enebo added a comment -

closing since second comments code snippet shows neo4j working with JRuby. Open new issue with any other more specific neo4j problems you encounter.

Show
Thomas E Enebo added a comment - closing since second comments code snippet shows neo4j working with JRuby. Open new issue with any other more specific neo4j problems you encounter.

People

Vote (0)
Watch (2)

Dates

  • Created:
    Updated:
    Resolved: