SqlSessionFactory with multiple xml mappers

38 views
Skip to first unread message

Sreekanth Vanguru

unread,
Jun 12, 2019, 2:34:10 PM6/12/19
to mybatis-user
Hello,

I've a requirement where I need to create SqlSessionFactory with multiple xml mapper files and name of the file needs to provided programmatically i.e. it's not hard coded. Is there some way to achieve what I want? All the examples that I've seen show the mapper.xml is hardcoded in mybatis-xml file directly.

sreekanth

Guy Rouillier

unread,
Jun 13, 2019, 4:22:14 AM6/13/19
to mybati...@googlegroups.com
Sure, see the section titled "2.1.3 Building SqlSessionFactory without XML" in the MyBatis User's Guide.

--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/372ad121-8a8d-4ee5-a096-9eb1dae7fb3d%40googlegroups.com.

Sreekanth Vanguru

unread,
Jun 13, 2019, 9:43:31 AM6/13/19
to mybatis-user
Guy,

thanks for the reply but I think you got me wrong. I want to use mapper xml files but I don't know the name of file ahead of time, so I can't hard code it in mybatis.cfg like this

<mappers>
    <mapper resource="/Mapper.xml" />
</mappers>

I would like to invoke a function and provide "mapper.xml" as an argument. 

I see that we can do something like this where "mapperInputStream" is stream from resource "mapper.xml". 

SqlSessionFactoryBuilder().build(mapperInputStream, DbProperties);

But I also another requirement where I need to provide multiple mapper.xml files for "SqlSessionFactoryBuilder" as my mapper statements are split into multiple files. is that possible to do?

Sreekanth

Sreekanth Vanguru

unread,
Jun 13, 2019, 10:30:07 AM6/13/19
to mybatis-user
Guy,

Sorry, my bad.. I understood SqlSessionFactory.build() api wrong... I'm good now.

sreekanth


On Wednesday, June 12, 2019 at 2:34:10 PM UTC-4, Sreekanth Vanguru wrote:
Reply all
Reply to author
Forward
0 new messages