Using JRuby with myBatis?

Does anyone know how to use myBatis with JRruby ?

I tried the following:

require “rubygems”
require “java”
require ‘jruby/core_ext’

java_import “org.apache.ibatis.io.Resources”
java_import “java.io.InputStream”
java_import “org.apache.ibatis.session.SqlSessionFactory”
java_import “org.apache.ibatis.session.SqlSessionFactoryBuilder”

inputStream = Resources::getResourceAsStream(“mybatis-config.xml”)

class Vkprlist
attr_accessor :name
end

Vkprlist.become_java!

sqlSessionFactory = SqlSessionFactoryBuilder.new.build(inputStream)

But I get:

Error building SqlSession.

The error may exist in VkprlistMapper.xml

Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL

Mapper Configuration. Cause: java.lang.RuntimeException: Error parsing
Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error
resolving class . Cause: org.apache.ibatis.type.TypeException: Could not
resolve type alias ‘Vkprlist’. Cause: java.lang.ClassNotFoundException:
Cannot find class: Vkprlist
(root) at test.rb:18

Regards
Roger

BTW: I’m using JRuby-1.6.7.2

just have a look at the Vkprlist which java class it is after
Vkprlist.become_java!

Vkprlist.java_class

it should be something like
rubyobj.Vkprlist

this is the one you need to use for myBatis xml-config.

I never used myBatis but what you wrote sounded familiar to what we
tried to do with

https://github.com/mkristian/jibernate

(which we postponed until datamapper-2.0 shaping up)

  • Kristian

On Fri, Aug 24, 2012 at 7:53 PM, Roger G. [email protected] wrote:

Does anyone know how to use myBatis with JRruby ?

No, and not familiar with it… From google, I can see it does help
connecting to SQL and it’s in java.

So quite likely you’re using jdbc. After reading some of the
documentation, it looks much more complex than traditional ruby ORM
like Sequel/DataMapper/ActiveRecord with jdbc connectors.

Though it’s always nice to use pure java libraries in jruby, for this
once, I would strongly advise to stick to simple ORM mentioned above,
unless all your business logic is already mapped using myBatis.

(I for one use Sequel)


Christian

https://github.com/mkristian/jibernate

wrong it is now

Hi thanks for the reply. But using rubyobj.Vkprlist instead of Vkrplist
leads to the same error.

Regards Roger

Am 26.08.2012 um 11:30 schrieb kristian [email protected]: