ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Chris Bowman <ch...@phoros.co.uk>
Subject Dynamic Select problem
Date Wed, 05 Apr 2006 12:54:06 GMT
Hi All,

I have a problem with a dynamic select, and having searched the archive 
I have found no answer.

The sutuation:

I have a database where customers can add user defined fields to each 
table, so any data access framework I use must be able to dynamically 
create select statements to handle these unknown fields (the framework 
must work across different customer databases with different user 
defined fields).

All user defined fields begin with 'U_', so I initially do a select to 
get a List of these fields (the table is called Customer)
    results = sqlMap.queryForList("mapper.getCustomerUserFields", null);

This worls fine, and I have a List of user defined Customer fields. Next 
stage is to get the actual dynamic select of the Customer table done. I 
use a parameter class which contains the List and a Customer ID, defined 
as follows:

    <parameterMap id="custParamMap" 
    <parameter property="list"/>
    <parameter property="id"/>

I then use the param class to search for specific customers (and their 
dynamic field values):

    <statement id="getPageFields2" parameterMap="custParamMap" 
    <iterate property="list">
    where Customer.id = #id#

I turned debug on via Log4j, and got this output:

DEBUG 04-05 13:37:55 {pstm-100004} PreparedStatement:  SELECT 
Customer.Serial_Num  ,?  ,?  FROM Customer where customer.id = ?   
DEBUG 04-05 13:37:55 {pstm-100004} Parameters: [U_Destination, U_Resort, 
1]  (Log4jImpl.java:22)
DEBUG 04-05 13:37:55 {pstm-100004} Types: [java.lang.String, 
java.lang.String, java.lang.Integer]  (Log4jImpl.java:22)
DEBUG 04-05 13:37:55 {rset-100005} ResultSet  (Log4jImpl.java:22)
DEBUG 04-05 13:37:55 {rset-100005} Header: [Serial_Num, expr2, expr3]  
DEBUG 04-05 13:37:55 {rset-100005} Result: [1, U_Destination, U_Resort]  

As you can see, the dynamic select is simply treating the List values as 
fixed values rather than column names, and returning them as is. A 
toString on the result map gives:
    {expr2=U_Destination, expr3=U_Resort, Serial_Num=1}

Is there anything I am missing here? I seem to be doing this correctly, 
but I am relatively new to iBatis.


Chris Bowman

View raw message