Re: mybatis-scala 1.0-Beta2

32 views
Skip to first unread message

Frank Martínez

unread,
Oct 6, 2012, 5:39:44 PM10/6/12
to mybati...@googlegroups.com
Hi Bandar,

mybatis-scala 1.0-Beta2 is binary compatible with mybatis 3.1.0 but
not with 3.1.1.

Beta3 will be binary compatible with 3.1.1. but it will break backward
compatibility because of some internal API changes in mybatis 3.1.1.

I am afraid 3.2 will break backward compatibility too because
mybatis-scala relies on some internal APIs. So while mybatis maintains
its backward compatibility in all of its public APIs it doesn't at
internal APIs.

We are working on the separation of the configuration model and the
runtime model in mybatis core, so I hope after 3.2 it would be easier
to maintain backward compatibility starting at 3.2, so the 1.0-GA
release of mybatis-scala will be released after mybatis core 3.2.

Are you interested in a particular 3.1.1 feature?

On Sat, Oct 6, 2012 at 12:53 AM, Bandar Bandirsen <back...@gmail.com> wrote:
> Hi,
>
> is mybatis-scala 1.0-Beta2 binary compatible with mybatis 3.1.1 release ?
>
>
>



--
Frank D. Martínez M.

Bandar Bandirsen

unread,
Oct 13, 2012, 2:52:31 AM10/13/12
to mybati...@googlegroups.com
Hi Frank,

Sorry for late reply,
Currently I don't need particular feature from my batis 3.1.1, I just want try lastest release.
Mybatis-scala Beta2 work nice with my scala code, thank you.

BTW, I now stuck on how to map a query to an immutable case class using constructor, if the case class has collection(eg: List etc) as their constructor argument.

eg:

case class Kid(id: Int, name: String)
case class Daddy( id: Int, name: String, myKids: List[Kid] )

mybatis-dao
------------------

object DAO {
  val kidResultMap = new ResultMap[Kid] {
    idArg( column = "id", javaType = T[Int] )
    arg( column="name", javaType = T[String] )
  }
}

  val daddyResultMap = new ResultMap[Daddy] {
    idArg( column = "id", javaType = T[Int] )
    arg( column = "name", javaType = T[String] )
    arg( column = "myKids", javaType= T[List[Kid]], resultMap = kidResultMap) // not work,
    // I dont know how to tell mybatis that 'myKids' field is collection of Kid object from kidResultMap
  }
}

while for mutable version I can do this :

object DAO {
  val kidResultMap = new ResultMap[Kid] {
    id( column = "id", javaType = T[Int] )
    result( column="name", javaType = T[String] )
  }
}

  val daddyResultMap = new ResultMap[Daddy] {
    id( column = "id", javaType = T[Int] )
    result( column="name", javaType=T[String] )
    collection( column = "myKids", javaType= T[List[Kid]], resultMap = kidResultMap )  // this is work,  if 'myKids' property is mutable (var instead val)
  }
}

maybe this is mybatis missing feature, I'm still digging some information on this.
my current workaround, I map query result yo a hashmap, and then manually handling those immutable case class object creation using the hashmap result.

Any suggestion ?



Frank Martínez

unread,
Oct 13, 2012, 12:39:53 PM10/13/12
to mybati...@googlegroups.com
Hi Bandar,

It is because mybatis does not support collections in constructor
arguments without nested selects :(

So, if you want to set a collection in constructor, you must use:

arg( column = "myKids", javaType= T[List[Kid]], select = ChildSelectorObject)

where ChildSelectorObject is just another mapped statement.

The problem with this approach is the N+1 Queries problem.

Thanks for testing the scala api. We are planing some changes in the
mybatis core that will benefit the scala api a lot.

Cheers,

Frank.

Bandar Bandirsen

unread,
Oct 13, 2012, 7:44:03 PM10/13/12
to mybati...@googlegroups.com
Hi Frank

I think a little more boiler plate is better than N+1 problem, so i will stick with my current solution.
Once again thanks for great work mybatis + your scala api are really help me much.

Regards,
Bandirsen
Reply all
Reply to author
Forward
0 new messages