You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by JA <gi...@yahoo.com> on 2006/12/19 13:33:24 UTC

Re: Problem with iBATIS implementation. Solved!

Thank you so much!!!
It seems like I forgot to remove the "static" from the member variables of my RequestTemplateData class, and now it worked perfectly!
I feel really like a fool, but after so many hours over java code, the mind stops working for even elementary things like this!

Thank you again!


 ----- Original Message ----
From: Jeff Butler <je...@gmail.com>
To: user-java@ibatis.apache.org
Sent: Tuesday, December 19, 2006 2:05:09 PM
Subject: Re: Problem with iBATIS implementation.

Actually, I think it might be helpful to see your RequestTemplateData class.  Have you declared the member variables to be static?  Doing so could lead to the results you're seeing.  Member variables should not be static in this case.


 

Jeff Butler



 

On 12/19/06, JA <gi...@yahoo.com> wrote:
Hello!


I am new to iBATIS and I have experienced a problem in the most simple implementation of querying my database...


Here is the problem:

I have a database with some simple tables (the RDBMS is Sybase and I am using also the appropriate JDBC driver for use with iBATIS), and I try to run a simple query on one of them but while iBATIS seems to read all the rows of the table, it fills up a list with objects that all of them contain the data from the last row of the table... I run the same query with pure JDBC and I got the correct results ...  I have attached the xml and java code with this email, and I also have put it below:

_______________________________________

The xml and java code are following :


(The object "RequestTemplateData" has the appropriate getters and setters, i don;t think it needs to be listed)



The SqlMap piece:
__________________________________

<sqlMap namespace="TemplatesList">
<select id="getTemplatesList" resultClass="gr.forthnet.staff.objects.RequestTemplateData
">

<![CDATA[
select
RequestTemplateDataId as REQUESTTEMPLATEDATAID,
RequestTemplateId as REQUESTTEMPLATEID,
KeyId as KEYID,
Required as REQUIRED,
DefValue as DEFVALUE
from RequestTemplateData

]]>

</select>

__________________________________

The Java piece is here :

////////////////////////////////////////////////////////////////////////////////
//            iBATIS SQL MAPS TEST AREA        //

           try {
           String resource = "ibatis/SqlMapConfig.xml";

           Reader reader = Resources.getResourceAsReader(resource);

           SqlMapClient sqlMap = SqlMapClientBuilder.buildSqlMapClient
(reader);

           sqlMap.startTransaction();
           List<RequestTemplateData> TList= sqlMap.queryForList("getTemplatesList", null);

           sqlMap.commitTransaction();

           for (RequestTemplateData rtd : TList){

               System.out.print(rtd.getREQUESTTEMPLATEDATAID() + " ~ ");
               System.out.print(rtd.getREQUESTTEMPLATEID() + " ~ ");
               System.out.print(rtd.getKEYID() + " ~ ");

               System.out.print(rtd.getREQUIRED() + " ~ ");
               System.out.println(rtd.getDEFVALUE() + " \n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ");
           }

///////////////////////////////////////////////////////////////////////////////////////////////////////


The result output in my console is  (actually the last row of the table RequestTemplateData) :

10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~




while it should be (the outcome I get with pure JDBC):

1 ~ 1 ~ 1 ~ 0 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2 ~ 1 ~ 2 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3 ~ 1 ~ 3 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

4 ~ 1 ~ 7 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
5 ~ 1 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
6 ~ 2 ~ 1 ~ 0 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 ~ 2 ~ 2 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

8 ~ 2 ~ 3 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 ~ 2 ~ 7 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10 ~ 2 ~ 8 ~ 1 ~ null
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


I any help would be precious! If more of my listings or data are needed please let me know and I will send them!


Thank you

Dimitris



__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around
http://mail.yahoo.com










__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com