[jruby-user] Using JRuby with myBatis ?

36 views
Skip to first unread message

Roger Gilliar

unread,
Aug 24, 2012, 1:53:30 PM8/24/12
to JRuby Users
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
---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Christian MICHON

unread,
Aug 26, 2012, 5:13:13 AM8/26/12
to us...@jruby.codehaus.org
On Fri, Aug 24, 2012 at 7:53 PM, Roger Gilliar <ro...@gilliar.de> 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

kristian

unread,
Aug 26, 2012, 5:30:33 AM8/26/12
to us...@jruby.codehaus.org
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

kristian

unread,
Aug 26, 2012, 5:31:28 AM8/26/12
to us...@jruby.codehaus.org

Roger Gilliar

unread,
Aug 27, 2012, 5:08:50 PM8/27/12
to us...@jruby.codehaus.org
Hi thanks for the reply. But using rubyobj.Vkprlist instead of Vkrplist leads to the same error.

Regards Roger
Reply all
Reply to author
Forward
0 new messages