ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher.Mathru...@sybase.com
Subject Re: Distributed DataSources and SQL Maps
Date Fri, 24 Feb 2006 00:20:36 GMT

<br><font size=2 face="sans-serif">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.</font>
<br>
<br><font size=2 face="sans-serif">SqlMapClientFactoryBean 1</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;
--&gt;
sql-map-config-1.xml</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;
&nbsp; &nbsp; &nbsp; --&gt; Customer.xml</font>
<br>
<br><font size=2 face="sans-serif">SqlMapClientFactoryBean 2</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;
--&gt;
sql-map-config-2.xml</font>
<br><font size=2 face="sans-serif">&nbsp; &nbsp; &nbsp; &nbsp;
&nbsp;
&nbsp; &nbsp; &nbsp; --&gt; CustomerClass.xml</font>
<br>
<br><font size=2 face="sans-serif">From within Customer.xml, the CustomerResult
has the following:</font>
<br><font size=2>&nbsp; &nbsp; </font><font size=2 color=blue>&lt;</font><font
size=2 color=#800000>result</font><font size=2 color=red>
column</font><font size=2 color=blue>=&quot;</font><font size=2>customer_class</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
property</font><font size=2 color=blue>=&quot;</font><font size=2>customerClass</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
select</font><font size=2 color=blue>=&quot;</font><font size=2>CustomerClass-findByPrimaryKey</font><font
size=2 color=blue>&quot;/&gt;</font>
<br>
<br><font size=2 face="sans-serif">This throws the following exception
at runtime:</font>
<br><font size=2 face="Courier New">Cause: </font><font size=2 color=#000080
face="Courier New"><u>com.ibatis.sqlmap.client.SqlMapException</u></font><font
size=2 face="Courier New">:
There is no statement named CustomerClass.CustomerClass-findByPrimaryKey
in this SqlMap</font>
<br>
<br>
<br><font size=2 face="sans-serif">I've even tried the following:</font>
<br><font size=2>&nbsp; &nbsp; </font><font size=2 color=blue>&lt;</font><font
size=2 color=#800000>result</font><font size=2 color=red>
column</font><font size=2 color=blue>=&quot;</font><font size=2>customer_class</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
property</font><font size=2 color=blue>=&quot;</font><font size=2>customerClass</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
select</font><font size=2 color=blue>=&quot;</font><font size=2><b>CustomerClass.</b>CustomerClass-findByPrimaryKey</font><font
size=2 color=blue>&quot;/&gt;</font>
<br>
<br><font size=2 face="sans-serif">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.</font>
<br>
<br><font size=2 face="sans-serif">Thanks for all the suggestions.</font>
<br><font size=2 face="sans-serif"><br>
Chris Mathrusse<br>
christopher.mathrusse@sybase.com<br>
Sybase, Inc<br>
One Sybase Drive<br>
Dublin, CA 94568<br>
(925) 236-5553</font>
<br>
<br>
<br>
<table width=100%>
<tr valign=top>
<td width=40%><font size=1 face="sans-serif"><b>&quot;Eric Blue&quot;
&lt;ericblue76@gmail.com&gt;</b>
</font>
<p><font size=1 face="sans-serif">02/23/2006 02:13 PM</font>
<table border>
<tr valign=top>
<td bgcolor=white>
<div align=center><font size=1 face="sans-serif">Please respond to<br>
user-java@ibatis.apache.org</font></div></table>
<br>
<td width=59%>
<table width=100%>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">To</font></div>
<td valign=top><font size=1 face="sans-serif">user-java@ibatis.apache.org</font>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">cc</font></div>
<td valign=top>
<tr>
<td>
<div align=right><font size=1 face="sans-serif">Subject</font></div>
<td valign=top><font size=1 face="sans-serif">Re: Distributed DataSources
and SQL Maps</font></table>
<br>
<table>
<tr valign=top>
<td>
<td></table>
<br></table>
<br>
<br>
<br><font size=3>Hi Chris,<br>
<br>
I'm assuming that you're using the iBatis DAO framework. &nbsp;If so, then
you should probably have 2 SQL Map configuration files (each with their
respective statements and database property configuration). &nbsp;One file
contains the Customer resultMap and related statements, and the other contains
CustomerBilling. &nbsp;The dao.xml then has a distinct context entry for
each sqlmap configuration. &nbsp;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. </font><font size=2>Customer-findByPrimaryKey).
&nbsp;<br>
<br>
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. &nbsp;Select statement one is Customer-findByPrimaryKey,
and statement two is Billing-Customer-findByPrimaryKey. &nbsp;You can then
reuse the same sql by creating a global sql entry (</font><a href="http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+reuse+SQL-fragments"><font
size=2 color=blue><u>http://opensource2.atlassian.com/confluence/oss/display/IBATIS/How+do+I+reuse+SQL-fragments</u></font></a><font
size=2>).<br>
<br>
I hope this helps.</font><font size=3><br>
</font>
<br><font size=3>On 2/23/06, </font><a href=mailto:Christopher.Mathrusse@sybase.com><font
size=3 color=blue><b><u>Christopher.Mathrusse@sybase.com</u></b></font></a><font
size=3>
&lt;</font><a href=mailto:Christopher.Mathrusse@sybase.com><font size=3
color=blue><u>
Christopher.Mathrusse@sybase.com</u></font></a><font size=3>&gt;
wrote:</font>
<br><font size=2 face="sans-serif"><br>
My problem is as follows:</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
Customer (POJO) -&gt; CustomerDao -&gt; CustomerDaoImpl -&gt; CustomerSQLMap
-&gt; DataSource1</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
CustomerBilling (POJO) -&gt; CustomerBillingDao -&gt; CustomerBillingDaoImpl
-&gt; CustomerBillingSQLMap -&gt; DataSource2</font><font size=3> <br>
</font><font size=2 face="sans-serif"><br>
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:</font><font size=3> <br>
</font><font size=2><br>
 &nbsp; &nbsp; &nbsp; &nbsp;</font><font size=2 color=blue>&lt;</font><font
size=2 color=#800000>resultMap</font><font size=2 color=red>
id</font><font size=2 color=blue>=&quot;</font><font size=2>CustomerBillingResult</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
class</font><font size=2 color=blue>=&quot;</font><font size=2>com.sybase.cosmos.domain.CustomerBilling</font><font
size=2 color=blue>&quot;&gt;</font><font size=3>
</font><font size=2><br>
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;</font><font
size=2 color=blue>&lt;</font><font size=2 color=#800000>result</font><font
size=2 color=red>
column</font><font size=2 color=blue>=&quot;</font><font size=2>customer_no</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
property</font><font size=2 color=blue>=&quot;</font><font size=2>customer</font><font
size=2 color=blue>&quot;</font><font size=2 color=red>
select</font><font size=2 color=blue>=&quot;</font><font size=2>Customer-findByPrimaryKey</font><font
size=2 color=blue>&quot;/&gt;</font><font size=3>
<br>
<br>
</font><font size=2 face="sans-serif"><br>
The problem with the above SQL Map is that when the Customer-findByPrimaryKey
is invoked it is trying to use <b>DataSource2 </b>associated with the CustomerBillingDao,
not <b>DataSource1 </b>associated with the CustomerDao, so I get an exception
because the table does not exist within the CustomerBillingDao DataSource.</font><font
size=3>
<br>
</font><font size=2 face="sans-serif"><br>
How can I tell iBatis to use the correct DataSource for this query?</font><font size=3>
<br>
</font><font size=2 face="sans-serif"><br>
Thanks very much....</font><font size=3> </font><font size=2 face="sans-serif"><br>
<br>
Chris Mathrusse</font><font size=2 color=blue face="sans-serif"><u><br>
</u></font><a href=mailto:christopher.mathrusse@sybase.com target=_blank><font
size=2 color=blue face="sans-serif"><u>christopher.mathrusse@sybase.com</u></font></a><font
size=2 face="sans-serif"><br>
Sybase, Inc<br>
One Sybase Drive<br>
Dublin, CA 94568<br>
(925) 236-5553</font><font size=3> </font>
<br>
<br>

Mime
View raw message