ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sven.Boden" <list...@pandora.be>
Subject Re: Distributed DataSources and SQL Maps
Date Fri, 24 Feb 2006 08:18:25 GMT

Multiple Datasources was possible in v1.x of iBATIS, but it seems that it was kicked out for
being "too messy"... "advocating bad practices".

Regards,
Sven

>Van: March, Andres [mailto:amarch@soe.sony.com]
>Verzonden: vrijdag, februari 24, 2006 02:59 AM
>Aan: user-java@ibatis.apache.org
>Onderwerp: RE: Distributed DataSources and SQL Maps
>
>Can't say I know that hibernate does this well either.  Last time I used
>it you were pegged against one datasource.  I cannot think of a
>technical reason why this use case could not be satisfied but I'm sure
>we are in the minority to be requesting it.
>
> 
>
>________________________________
>
>From: Christopher.Mathrusse@sybase.com
>[mailto:Christopher.Mathrusse@sybase.com] 
>Sent: Thursday, February 23, 2006 4:31 PM
>To: user-java@ibatis.apache.org
>Subject: RE: Distributed DataSources and SQL Maps
>
> 
>
>
>I originally tried to have a single SqlMapClientFactoryBean and a single
>sql-map-config.xml file where all Dao's were declared. Spring then
>allowed me to assign the DataSource to the individual Dao's rather then
>to the SqlMapClientFactoryBean. I thought this would work but it
>appeared that once execution occurred in a SqlMap the same DataSource
>would be used for all other map statements. 
>
>Chris Mathrusse
>christopher.mathrusse@sybase.com
>Sybase, Inc
>One Sybase Drive
>Dublin, CA 94568
>(925) 236-5553 
>
>
>
>"March, Andres" <amarch@soe.sony.com> 
>
>02/23/2006 04:26 PM 
>
>Please respond to
>user-java@ibatis.apache.org
>
>To
>
><user-java@ibatis.apache.org> 
>
>cc
>
> 
>
>Subject
>
>RE: Distributed DataSources and SQL Maps
>
> 
>
> 
>
> 
>
>
>
>
>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