Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OrientDB's JDBC driver with ActiveRecord

What is the proper way of using OrientDB's JDBC driver with ActiveRecord?

I am trying to connect a Rails 3.2 application to OrientDB 1.4. I installed the gem activerecord-jdbc-adapter, and configured the database.yml as follows:

development:
  adapter: jdbc
  username: admin
  password: admin
  driver:   com.orientechnologies.orient.jdbc.OrientJdbcDriver
  url:      jdbc:orient:local:db/test_db2

I load the OrientDB's JDBC driver as follows:

# in config/application.rb:
require '/home/myuser/jars/orientdb-jdbc-1.4.0-all.jar'

The following exception is being thrown when the application starts (using rails s):

java.lang.NullPointerException
    at arjdbc.jdbc.RubyJdbcConnection.unmarshalResult(RubyJdbcConnection.java:1187)
    at arjdbc.jdbc.RubyJdbcConnection.set_native_database_types(RubyJdbcConnection.java:537)
    at arjdbc.jdbc.RubyJdbcConnection$INVOKER$i$0$0$set_native_database_types.call(RubyJdbcConnection$INVOKER$i$0$0$set_native_database_types.gen)
    ...

Is there something missing in my configuration? What is the proper way of using OrientDB's JDBC driver with ActiveRecord?

like image 701
Hebatu Allah Fahmy Avatar asked Jul 13 '13 12:07

Hebatu Allah Fahmy


1 Answers

While activerecord-jdbc-adapter (theoretically) supports any JDBC compilant driver, it uses APIs and makes a few assumptions that might work not so well for a few. Esp. with not-fully compliant drivers such as orientdb-jdbc (at least version 1.4) is.

In this case AR-JDBC tries to resolve supported types from the DB meta-data: http://git.io/s7g47A but since metadata.getTypeInfo() returns an unexpected null instead of an actual ResulSet object all fails badly. This might be improved by handling "null" types by overriding native_database_types method in Ruby and/or some additional code on AR-JDBC's side - although for OrientDB's "driver" it still might not be enough to get it fully functional with AR-JDBC ... sounds like a pretty good fit for an AR-JDBC extension (assuming OrientDB can handle the SQL that ActiveRecors/AREL will generate).

like image 58
kares Avatar answered Nov 05 '22 07:11

kares