Select join across multiple database

46 views
Skip to first unread message

varman seven

unread,
Nov 14, 2012, 11:15:51 PM11/14/12
to mybati...@googlegroups.com
Dear all,

I am newbie in mybatis, and I really like to use it in my project.
I need to work with multiple databases with different schema.
Let's say, the schema is something like this.

Database1
table1
table2

Database2
table3
table4

I would like to know what's the best practice of implementing such a kind of web application?
This is what I am planning to do, not sure it's working or not.

- Create only one mapper.xml

  <environments default="development">
    <environment id="development">
      <transactionManager type="JDBC"/>
      <dataSource type="POOLED">
        <property name="driver" value="${db.driver}"/>
        <property name="url" value="${db.host}${db.Database1}"/>
        <property name="username" value="${db.user}"/>
        <property name="password" value="${db.pass}"/>
      </dataSource>
    </environment>
  </environments>
  
  <typeAliases>
  <typeAlias type="com.model.Table1" alias="Table1" />
   <typeAlias type="com.model.Table2" alias="Table2" />
   <typeAlias type="com.model.Table3" alias="Table3" /> 
   <typeAlias type="com.model.Table4" alias="Table4" /> 
  </typeAliases>
  
  <mappers >
    <mapper resource="com/mapper/Table1.xml" />
    <mapper resource="com/mapper/Table2.xml" /> 
    <mapper resource="com/mapper/Table3.xml" /> 
    <mapper resource="com/mapper/Table4.xml" /> 
  </mappers>

Whenever I want to select join between tables of Database1 and Database2, I have to call DatabaseName.TableName.
Please give me some advise.

Reply all
Reply to author
Forward
0 new messages