ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "March, Andres" <ama...@soe.sony.com>
Subject RE: Distributed DataSources and SQL Maps
Date Fri, 24 Feb 2006 00:26:02 GMT
Seems like the requirement would be better satisfied by allowing
multiple datasources per SqlMapClient, not sure this is possible.  But
I'm interested in being able to query across dbs within the same parent
statement mapping as well.

 

________________________________

From: Christopher.Mathrusse@sybase.com
[mailto:Christopher.Mathrusse@sybase.com] 
Sent: Thursday, February 23, 2006 4:21 PM
To: user-java@ibatis.apache.org
Subject: Re: Distributed DataSources and SQL Maps

 


I am using Spring to manage the DAO framework. I've configured 2 SQL Map
configuration files and configured Spring to manage both of them. I've
created 2 SqlMapClientFactoryBeans and assigned the SQL Maps
appropriately. I've assigned separate DataSources to each
SqlMapClientFactoryBean so as to ensure that each Dao has the
appropriate DataSource. All seems to work well, until I attempt to
access one of the statements in a SqlMap that does not belong to the
SqlMap that is currently being executed. 

SqlMapClientFactoryBean 1 
        --> sql-map-config-1.xml 
                --> Customer.xml 

SqlMapClientFactoryBean 2 
        --> sql-map-config-2.xml 
                --> CustomerClass.xml 

>From within Customer.xml, the CustomerResult has the following: 
    <result column="customer_class" property="customerClass"
select="CustomerClass-findByPrimaryKey"/> 

This throws the following exception at runtime: 
Cause: com.ibatis.sqlmap.client.SqlMapException: There is no statement
named CustomerClass.CustomerClass-findByPrimaryKey in this SqlMap 


I've even tried the following: 
    <result column="customer_class" property="customerClass"
select="CustomerClass.CustomerClass-findByPrimaryKey"/> 

But this resulted in the same error. I don't how to reference the
CustomerClass SqlMap from within the Customer SqlMap when they are
loaded as two separate Maps. Perhaps I am missing something that will
tie them together. The only other way I can see this working is if I
glue these object together within the Dao layer, but that would get ugly
in my opinion. I would much rather do it in the SqlMap. 

Thanks for all the suggestions. 

Chris Mathrusse
christopher.mathrusse@sybase.com
Sybase, Inc
One Sybase Drive
Dublin, CA 94568
(925) 236-5553 



"Eric Blue" <ericblue76@gmail.com> 

02/23/2006 02:13 PM 

Please respond to
user-java@ibatis.apache.org

To

user-java@ibatis.apache.org 

cc

 

Subject

Re: Distributed DataSources and SQL Maps

 

 

 




Hi Chris,

I'm assuming that you're using the iBatis DAO framework.  If so, then
you should probably have 2 SQL Map configuration files (each with their
respective statements and database property configuration).  One file
contains the Customer resultMap and related statements, and the other
contains CustomerBilling.  The dao.xml then has a distinct context entry
for each sqlmap configuration.  I've used this setup to handle 3 or more
different data sources, however I never attempted to reference the same
statement across data sources (i.e. Customer-findByPrimaryKey).  

I'm not quite sure if this is needed (or will work), but if the setup I
described above does not work, then maybe you can try creating a
distinct select statement for each datasource.  Select statement one is
Customer-findByPrimaryKey, and statement two is
Billing-Customer-findByPrimaryKey.  You can then reuse the same sql by
creating a global sql entry
(http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I
+reuse+SQL-fragments
<http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I
+reuse+SQL-fragments> ).

I hope this helps.

On 2/23/06, Christopher.Mathrusse@sybase.com
<mailto:Christopher.Mathrusse@sybase.com>  <
Christopher.Mathrusse@sybase.com
<mailto:Christopher.Mathrusse@sybase.com> > wrote: 

My problem is as follows: 

Customer (POJO) -> CustomerDao -> CustomerDaoImpl -> CustomerSQLMap ->
DataSource1 

CustomerBilling (POJO) -> CustomerBillingDao -> CustomerBillingDaoImpl
-> CustomerBillingSQLMap -> DataSource2 

CustomerBilling object has a Customer object that is accessible with a
get method. What I would like to do in the CustomerBilling SQL Map is as
follows: 

       <resultMap id="CustomerBillingResult"
class="com.sybase.cosmos.domain.CustomerBilling"> 
               <result column="customer_no" property="customer"
select="Customer-findByPrimaryKey"/> 


The problem with the above SQL Map is that when the
Customer-findByPrimaryKey is invoked it is trying to use DataSource2
associated with the CustomerBillingDao, not DataSource1 associated with
the CustomerDao, so I get an exception because the table does not exist
within the CustomerBillingDao DataSource. 

How can I tell iBatis to use the correct DataSource for this query? 

Thanks very much.... 

Chris Mathrusse
christopher.mathrusse@sybase.com
<mailto:christopher.mathrusse@sybase.com> 
Sybase, Inc
One Sybase Drive
Dublin, CA 94568
(925) 236-5553 


Mime
View raw message