SqlSessionFactory with multiple xml mappers

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

SqlSessionFactory with multiple xml mappers

sreekanth.r.vanguru
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/372ad121-8a8d-4ee5-a096-9eb1dae7fb3d%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: SqlSessionFactory with multiple xml mappers

Guy Rouillier-2
Sure, see the section titled "2.1.3 Building SqlSessionFactory without XML" in the MyBatis User's Guide.

--
Guy Rouillier

On 6/12/2019 2:34:10 PM, "Sreekanth Vanguru" <[hidden email]> wrote:

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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/372ad121-8a8d-4ee5-a096-9eb1dae7fb3d%40googlegroups.com.

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/emceb3b092-b96a-40d3-89c9-f75680b6c733%40asus.
Reply | Threaded
Open this post in threaded view
|

Re: SqlSessionFactory with multiple xml mappers

sreekanth.r.vanguru
In reply to this post by sreekanth.r.vanguru
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




On Wednesday, June 12, 2019 at 2:34:10 PM UTC-4, Sreekanth Vanguru wrote:
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/102b2b53-c232-410e-8803-9b1de2d8ba1a%40googlegroups.com.
Reply | Threaded
Open this post in threaded view
|

Re: SqlSessionFactory with multiple xml mappers

sreekanth.r.vanguru
In reply to this post by sreekanth.r.vanguru
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:
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

--
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 [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/mybatis-user/afe8a1b5-d9a1-4412-ace1-9b80f7161346%40googlegroups.com.