You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Agilan Palani <ag...@bntasia.com> on 2005/10/05 14:46:58 UTC

Multiple Databases - Multiple Context

Hi

 

            I need Ibatis to provide access to two different databases.

            After going through the forums I found that it can be achieved
by

            1. Configuring two <context> tags in the dao.xml, 

2. While getting the DAO objects, use the following method

            getDaoManager().getDao(UserDAO.class, contextId ) to retrieve
the objects,

            they would access the correct database defined for that context.

 

            Question here is how do I define/declare a contextId to the
<context> ?

            I checked the http://www.ibatis.com/dtd/dao-2.dtd and there is
no way that 

I can specify an ID to the context tag.

 

Is there any other way to do this?

 

 

Thanks in advance

Agilan


Re: Multiple Databases - Multiple Context

Posted by Larry Meadors <lm...@apache.org>.
Uhm, by using the id attribute?

<context id="blah">
  ...
</context>

That is the easiest way to have two seperate sets of DAO classes -
i.e., setting up oracle and M$SQL, for instance.

Another approach to this is to pass properties into the
DaoManagerBuilder at runtime, that is the easiest way to have the
exact same set of dao classes with just different database
connections.

Larry


On 10/5/05, Agilan Palani <ag...@bntasia.com> wrote:
>
>
>
> Hi
>
>
>
>             I need Ibatis to provide access to two different databases.
>
>             After going through the forums I found that it can be achieved
> by
>
>             1. Configuring two <context> tags in the dao.xml,
>
> 2. While getting the DAO objects, use the following method
>
>             getDaoManager().getDao(UserDAO.class, contextId ) to retrieve
> the objects,
>
>             they would access the correct database defined for that context.
>
>
>
>             Question here is how do I define/declare a contextId to the
> <context> ?
>
>             I checked the
> http://www.ibatis.com/dtd/dao-2.dtd and there is no way
> that
>
> I can specify an ID to the context tag.
>
>
>
> Is there any other way to do this?
>
>
>
>
>
> Thanks in advance
>
> Agilan