You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-cs@ibatis.apache.org by Dorin Manoli <Do...@dataireland.ie> on 2006/11/16 15:58:33 UTC
QueryForObject bug ?
Hi people, I stuck with a problem for a few hours till I figured out that it may be a iBatis Error..
Steps to reproduce. I have a Table with data (see atach)
I have the xml maped statements
<select id="GetCompanyById" resultMap="CompaniesResultMap" parameterClass="Hashtable">
select companyId,serial,regNo,regDate,legalFormId,
vatno,originCountry,officeHr,employees,businessOverseas,
printOptions,member,mail,indica,journl,comptr,isLocked, replyCodeId from companies
<isGreaterThan property ="CompanyId" compareValue ="0">
where companyId = #CompanyId#
</isGreaterThan>
order by companyId
</select>
....... ....
Then I wrote a mapped class... with a method
public Company GetCompanyById(long companyId)
{
Company cp = new Company();
try
{
Hashtable queryParams = new Hashtable();
queryParams.Add("CompanyId", companyId);
cp = (Company)KompassMapper.Instance().QueryForObject("GetCompanyById",queryParams);
}
catch
{
throw;
}
return cp;
}
Unit test to invoke this metnod:
[Test]
public void GetWrongCompanyById()
{
CompaniesMap companyMap = new CompaniesMap();
//Company getCompany = new Company();
Company company=companyMap.GetCompanyById(-1);
Assert.AreEqual(0F,company.CompanyId);
}
Unit test result is :
KompassDataLayer.Test.CompaniesTest.GetWrongCompanyById :
expected: <0>
but was: <29>
so I was expected a null value instead of first record from the table .
VS watch : cp
BussOverseas 0 int
bussOverseas 0 int
changed false bool
Changed false bool
CompanyId 29 long
companyId 29 long
Comptr null string
comptr null string
emploees 100 int
Indica "MSE" string
indica "MSE" string
isLocked false bool
Journl "60" string
journl "60" string
legalFormId 0 int
LegalFormId 0 int
Locked false bool
mail "D" string
Mail "D" string
Member "2 D" string
member "2 D" string
NoEmpl 100 int
OfficeHr "M-Fr: 9.00-17.00" string
officeHr "M-Fr: 9.00-17.00" string
Origin "IE" string
originCountry "IE" string
printOptions "1P" string
Prtopt "1P" string
RegDate "2001" string
regDate "2001" string
regNo "123456N" string
RegNo "123456N" string
ReplyCodeId 0 int
replyCodeId 0 int
Serial "70950520" string
serial "70950520" string
vatno "" string
VatNo "" string
RE: QueryForObject bug ?
Posted by Dorin Manoli <Do...@dataireland.ie>.
Sorry guys I got it. The problem is in xml map file
<isGreaterThan property ="CompanyId" compareValue="0">
. . . .
ID is -1 and not satisfy the condition, and where clause is ignored..
-----Original Message-----
From: Dorin Manoli [mailto:Dorin.Manoli@dataireland.ie]
Sent: Thursday, November 16, 2006 3:50 PM
To: user-cs@ibatis.apache.org
Subject: RE: QueryForObject bug ?
Of course .. I use MySQL 5
-----Original Message-----
From: Dorin Manoli [mailto:Dorin.Manoli@dataireland.ie]
Sent: Thursday, November 16, 2006 3:38 PM
To: user-cs@ibatis.apache.org; lmeadors@apache.org
Subject: RE: QueryForObject bug ?
It is .Net, also I changed the parameterClass to parameterClass="long"
And then Invoked QueryForList and I got all records in table..
Then tested with parameterClass="Company" and result is the same..
-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf
Of Larry Meadors
Sent: Thursday, November 16, 2006 3:09 PM
To: user-cs@ibatis.apache.org
Subject: Re: QueryForObject bug ?
Interesting, in the Java version, if there is more than one record
returned, we throw an exception. Looks like in the .NET version, you
get row #1.
Larry
On 11/16/06, Dorin Manoli <Do...@dataireland.ie> wrote:
>
>
>
>
> Hi people, I stuck with a problem for a few hours till I figured out
that it
> may be a iBatis Error..
>
>
>
> Steps to reproduce. I have a Table with data (see atach)
>
>
>
> I have the xml maped statements
>
> <select id="GetCompanyById" resultMap="CompaniesResultMap"
> parameterClass="Hashtable">
>
> select
> companyId,serial,regNo,regDate,legalFormId,
>
>
> vatno,originCountry,officeHr,employees,businessOverseas,
>
>
> printOptions,member,mail,indica,journl,comptr,isLocked,
> replyCodeId from companies
>
> <isGreaterThan property ="CompanyId" compareValue
="0">
>
> where companyId = #CompanyId#
>
> </isGreaterThan>
>
> order by companyId
>
> </select>
>
> ....... ....
>
> Then I wrote a mapped class... with a method
>
> public Company GetCompanyById(long companyId)
>
> {
>
> Company cp = new Company();
>
>
>
> try
>
> {
>
> Hashtable queryParams = new Hashtable();
>
> queryParams.Add("CompanyId", companyId);
>
>
>
> cp =
>
(Company)KompassMapper.Instance().QueryForObject("GetCompanyById",queryP
arams);
>
>
>
> }
>
> catch
>
> {
>
> throw;
>
> }
>
>
>
> return cp;
>
> }
>
> Unit test to invoke this metnod:
>
> [Test]
>
> public void GetWrongCompanyById()
>
> {
>
> CompaniesMap companyMap = new CompaniesMap();
>
> //Company getCompany = new Company();
>
>
>
> Company company=companyMap.GetCompanyById(-1);
>
> Assert.AreEqual(0F,company.CompanyId);
>
>
>
> }
>
> Unit test result is :
>
> KompassDataLayer.Test.CompaniesTest.GetWrongCompanyById :
>
> expected: <0>
>
> but was: <29>
>
>
>
> so I was expected a null value instead of first record from the table
.
>
>
>
> VS watch : cp
>
> BussOverseas 0 int
>
> bussOverseas 0 int
>
> changed false bool
>
> Changed false bool
>
> CompanyId 29 long
>
> companyId 29 long
>
> Comptr null string
>
> comptr null string
>
> emploees 100 int
>
> Indica "MSE" string
>
> indica "MSE" string
>
> isLocked false bool
>
> Journl "60" string
>
> journl "60" string
>
> legalFormId 0 int
>
> LegalFormId 0 int
>
> Locked false bool
>
> mail "D" string
>
> Mail "D" string
>
> Member "2 D" string
>
> member "2 D" string
>
> NoEmpl 100 int
>
> OfficeHr "M-Fr: 9.00-17.00" string
>
> officeHr "M-Fr: 9.00-17.00" string
>
> Origin "IE" string
>
> originCountry "IE" string
>
> printOptions "1P" string
>
> Prtopt "1P" string
>
> RegDate "2001" string
>
> regDate "2001" string
>
> regNo "123456N" string
>
> RegNo "123456N" string
>
> ReplyCodeId 0 int
>
> replyCodeId 0 int
>
> Serial "70950520" string
>
> serial "70950520" string
>
> vatno "" string
>
> VatNo "" string
>
>
>
>
>
>
RE: QueryForObject bug ?
Posted by Dorin Manoli <Do...@dataireland.ie>.
Of course .. I use MySQL 5
-----Original Message-----
From: Dorin Manoli [mailto:Dorin.Manoli@dataireland.ie]
Sent: Thursday, November 16, 2006 3:38 PM
To: user-cs@ibatis.apache.org; lmeadors@apache.org
Subject: RE: QueryForObject bug ?
It is .Net, also I changed the parameterClass to parameterClass="long"
And then Invoked QueryForList and I got all records in table..
Then tested with parameterClass="Company" and result is the same..
-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf
Of Larry Meadors
Sent: Thursday, November 16, 2006 3:09 PM
To: user-cs@ibatis.apache.org
Subject: Re: QueryForObject bug ?
Interesting, in the Java version, if there is more than one record
returned, we throw an exception. Looks like in the .NET version, you
get row #1.
Larry
On 11/16/06, Dorin Manoli <Do...@dataireland.ie> wrote:
>
>
>
>
> Hi people, I stuck with a problem for a few hours till I figured out
that it
> may be a iBatis Error..
>
>
>
> Steps to reproduce. I have a Table with data (see atach)
>
>
>
> I have the xml maped statements
>
> <select id="GetCompanyById" resultMap="CompaniesResultMap"
> parameterClass="Hashtable">
>
> select
> companyId,serial,regNo,regDate,legalFormId,
>
>
> vatno,originCountry,officeHr,employees,businessOverseas,
>
>
> printOptions,member,mail,indica,journl,comptr,isLocked,
> replyCodeId from companies
>
> <isGreaterThan property ="CompanyId" compareValue
="0">
>
> where companyId = #CompanyId#
>
> </isGreaterThan>
>
> order by companyId
>
> </select>
>
> ....... ....
>
> Then I wrote a mapped class... with a method
>
> public Company GetCompanyById(long companyId)
>
> {
>
> Company cp = new Company();
>
>
>
> try
>
> {
>
> Hashtable queryParams = new Hashtable();
>
> queryParams.Add("CompanyId", companyId);
>
>
>
> cp =
>
(Company)KompassMapper.Instance().QueryForObject("GetCompanyById",queryP
arams);
>
>
>
> }
>
> catch
>
> {
>
> throw;
>
> }
>
>
>
> return cp;
>
> }
>
> Unit test to invoke this metnod:
>
> [Test]
>
> public void GetWrongCompanyById()
>
> {
>
> CompaniesMap companyMap = new CompaniesMap();
>
> //Company getCompany = new Company();
>
>
>
> Company company=companyMap.GetCompanyById(-1);
>
> Assert.AreEqual(0F,company.CompanyId);
>
>
>
> }
>
> Unit test result is :
>
> KompassDataLayer.Test.CompaniesTest.GetWrongCompanyById :
>
> expected: <0>
>
> but was: <29>
>
>
>
> so I was expected a null value instead of first record from the table
.
>
>
>
> VS watch : cp
>
> BussOverseas 0 int
>
> bussOverseas 0 int
>
> changed false bool
>
> Changed false bool
>
> CompanyId 29 long
>
> companyId 29 long
>
> Comptr null string
>
> comptr null string
>
> emploees 100 int
>
> Indica "MSE" string
>
> indica "MSE" string
>
> isLocked false bool
>
> Journl "60" string
>
> journl "60" string
>
> legalFormId 0 int
>
> LegalFormId 0 int
>
> Locked false bool
>
> mail "D" string
>
> Mail "D" string
>
> Member "2 D" string
>
> member "2 D" string
>
> NoEmpl 100 int
>
> OfficeHr "M-Fr: 9.00-17.00" string
>
> officeHr "M-Fr: 9.00-17.00" string
>
> Origin "IE" string
>
> originCountry "IE" string
>
> printOptions "1P" string
>
> Prtopt "1P" string
>
> RegDate "2001" string
>
> regDate "2001" string
>
> regNo "123456N" string
>
> RegNo "123456N" string
>
> ReplyCodeId 0 int
>
> replyCodeId 0 int
>
> Serial "70950520" string
>
> serial "70950520" string
>
> vatno "" string
>
> VatNo "" string
>
>
>
>
>
>
RE: QueryForObject bug ?
Posted by Dorin Manoli <Do...@dataireland.ie>.
It is .Net, also I changed the parameterClass to parameterClass="long"
And then Invoked QueryForList and I got all records in table..
Then tested with parameterClass="Company" and result is the same..
-----Original Message-----
From: larry.meadors@gmail.com [mailto:larry.meadors@gmail.com] On Behalf
Of Larry Meadors
Sent: Thursday, November 16, 2006 3:09 PM
To: user-cs@ibatis.apache.org
Subject: Re: QueryForObject bug ?
Interesting, in the Java version, if there is more than one record
returned, we throw an exception. Looks like in the .NET version, you
get row #1.
Larry
On 11/16/06, Dorin Manoli <Do...@dataireland.ie> wrote:
>
>
>
>
> Hi people, I stuck with a problem for a few hours till I figured out
that it
> may be a iBatis Error..
>
>
>
> Steps to reproduce. I have a Table with data (see atach)
>
>
>
> I have the xml maped statements
>
> <select id="GetCompanyById" resultMap="CompaniesResultMap"
> parameterClass="Hashtable">
>
> select
> companyId,serial,regNo,regDate,legalFormId,
>
>
> vatno,originCountry,officeHr,employees,businessOverseas,
>
>
> printOptions,member,mail,indica,journl,comptr,isLocked,
> replyCodeId from companies
>
> <isGreaterThan property ="CompanyId" compareValue
="0">
>
> where companyId = #CompanyId#
>
> </isGreaterThan>
>
> order by companyId
>
> </select>
>
> ....... ....
>
> Then I wrote a mapped class... with a method
>
> public Company GetCompanyById(long companyId)
>
> {
>
> Company cp = new Company();
>
>
>
> try
>
> {
>
> Hashtable queryParams = new Hashtable();
>
> queryParams.Add("CompanyId", companyId);
>
>
>
> cp =
>
(Company)KompassMapper.Instance().QueryForObject("GetCompanyById",queryP
arams);
>
>
>
> }
>
> catch
>
> {
>
> throw;
>
> }
>
>
>
> return cp;
>
> }
>
> Unit test to invoke this metnod:
>
> [Test]
>
> public void GetWrongCompanyById()
>
> {
>
> CompaniesMap companyMap = new CompaniesMap();
>
> //Company getCompany = new Company();
>
>
>
> Company company=companyMap.GetCompanyById(-1);
>
> Assert.AreEqual(0F,company.CompanyId);
>
>
>
> }
>
> Unit test result is :
>
> KompassDataLayer.Test.CompaniesTest.GetWrongCompanyById :
>
> expected: <0>
>
> but was: <29>
>
>
>
> so I was expected a null value instead of first record from the table
.
>
>
>
> VS watch : cp
>
> BussOverseas 0 int
>
> bussOverseas 0 int
>
> changed false bool
>
> Changed false bool
>
> CompanyId 29 long
>
> companyId 29 long
>
> Comptr null string
>
> comptr null string
>
> emploees 100 int
>
> Indica "MSE" string
>
> indica "MSE" string
>
> isLocked false bool
>
> Journl "60" string
>
> journl "60" string
>
> legalFormId 0 int
>
> LegalFormId 0 int
>
> Locked false bool
>
> mail "D" string
>
> Mail "D" string
>
> Member "2 D" string
>
> member "2 D" string
>
> NoEmpl 100 int
>
> OfficeHr "M-Fr: 9.00-17.00" string
>
> officeHr "M-Fr: 9.00-17.00" string
>
> Origin "IE" string
>
> originCountry "IE" string
>
> printOptions "1P" string
>
> Prtopt "1P" string
>
> RegDate "2001" string
>
> regDate "2001" string
>
> regNo "123456N" string
>
> RegNo "123456N" string
>
> ReplyCodeId 0 int
>
> replyCodeId 0 int
>
> Serial "70950520" string
>
> serial "70950520" string
>
> vatno "" string
>
> VatNo "" string
>
>
>
>
>
>
Re: QueryForObject bug ?
Posted by Larry Meadors <lm...@apache.org>.
Interesting, in the Java version, if there is more than one record
returned, we throw an exception. Looks like in the .NET version, you
get row #1.
Larry
On 11/16/06, Dorin Manoli <Do...@dataireland.ie> wrote:
>
>
>
>
> Hi people, I stuck with a problem for a few hours till I figured out that it
> may be a iBatis Error..
>
>
>
> Steps to reproduce. I have a Table with data (see atach)
>
>
>
> I have the xml maped statements
>
> <select id="GetCompanyById" resultMap="CompaniesResultMap"
> parameterClass="Hashtable">
>
> select
> companyId,serial,regNo,regDate,legalFormId,
>
>
> vatno,originCountry,officeHr,employees,businessOverseas,
>
>
> printOptions,member,mail,indica,journl,comptr,isLocked,
> replyCodeId from companies
>
> <isGreaterThan property ="CompanyId" compareValue ="0">
>
> where companyId = #CompanyId#
>
> </isGreaterThan>
>
> order by companyId
>
> </select>
>
> ……. ….
>
> Then I wrote a mapped class… with a method
>
> public Company GetCompanyById(long companyId)
>
> {
>
> Company cp = new Company();
>
>
>
> try
>
> {
>
> Hashtable queryParams = new Hashtable();
>
> queryParams.Add("CompanyId", companyId);
>
>
>
> cp =
> (Company)KompassMapper.Instance().QueryForObject("GetCompanyById",queryParams);
>
>
>
> }
>
> catch
>
> {
>
> throw;
>
> }
>
>
>
> return cp;
>
> }
>
> Unit test to invoke this metnod:
>
> [Test]
>
> public void GetWrongCompanyById()
>
> {
>
> CompaniesMap companyMap = new CompaniesMap();
>
> //Company getCompany = new Company();
>
>
>
> Company company=companyMap.GetCompanyById(-1);
>
> Assert.AreEqual(0F,company.CompanyId);
>
>
>
> }
>
> Unit test result is :
>
> KompassDataLayer.Test.CompaniesTest.GetWrongCompanyById :
>
> expected: <0>
>
> but was: <29>
>
>
>
> so I was expected a null value instead of first record from the table .
>
>
>
> VS watch : cp
>
> BussOverseas 0 int
>
> bussOverseas 0 int
>
> changed false bool
>
> Changed false bool
>
> CompanyId 29 long
>
> companyId 29 long
>
> Comptr null string
>
> comptr null string
>
> emploees 100 int
>
> Indica "MSE" string
>
> indica "MSE" string
>
> isLocked false bool
>
> Journl "60" string
>
> journl "60" string
>
> legalFormId 0 int
>
> LegalFormId 0 int
>
> Locked false bool
>
> mail "D" string
>
> Mail "D" string
>
> Member "2 D" string
>
> member "2 D" string
>
> NoEmpl 100 int
>
> OfficeHr "M-Fr: 9.00-17.00" string
>
> officeHr "M-Fr: 9.00-17.00" string
>
> Origin "IE" string
>
> originCountry "IE" string
>
> printOptions "1P" string
>
> Prtopt "1P" string
>
> RegDate "2001" string
>
> regDate "2001" string
>
> regNo "123456N" string
>
> RegNo "123456N" string
>
> ReplyCodeId 0 int
>
> replyCodeId 0 int
>
> Serial "70950520" string
>
> serial "70950520" string
>
> vatno "" string
>
> VatNo "" string
>
>
>
>
>
>
RE: QueryForObject bug ?
Posted by Dorin Manoli <Do...@dataireland.ie>.
Sorry I forgot to attach;
________________________________
From: Dorin Manoli [mailto:Dorin.Manoli@dataireland.ie]
Sent: Thursday, November 16, 2006 2:59 PM
To: user-cs@ibatis.apache.org
Subject: QueryForObject bug ?
Hi people, I stuck with a problem for a few hours till I figured out
that it may be a iBatis Error..
Steps to reproduce. I have a Table with data (see atach)
I have the xml maped statements
<select id="GetCompanyById" resultMap="CompaniesResultMap"
parameterClass="Hashtable">
select companyId,serial,regNo,regDate,legalFormId,
vatno,originCountry,officeHr,employees,businessOverseas,
printOptions,member,mail,indica,journl,comptr,isLocked, replyCodeId
from companies
<isGreaterThan property ="CompanyId" compareValue
="0">
where companyId = #CompanyId#
</isGreaterThan>
order by companyId
</select>
....... ....
Then I wrote a mapped class... with a method
public Company GetCompanyById(long companyId)
{
Company cp = new Company();
try
{
Hashtable queryParams = new Hashtable();
queryParams.Add("CompanyId", companyId);
cp =
(Company)KompassMapper.Instance().QueryForObject("GetCompanyById",queryP
arams);
}
catch
{
throw;
}
return cp;
}
Unit test to invoke this metnod:
[Test]
public void GetWrongCompanyById()
{
CompaniesMap companyMap = new CompaniesMap();
//Company getCompany = new Company();
Company company=companyMap.GetCompanyById(-1);
Assert.AreEqual(0F,company.CompanyId);
}
Unit test result is :
KompassDataLayer.Test.CompaniesTest.GetWrongCompanyById :
expected: <0>
but was: <29>
so I was expected a null value instead of first record from the table .
VS watch : cp
BussOverseas 0 int
bussOverseas 0 int
changed false bool
Changed false bool
CompanyId 29 long
companyId 29 long
Comptr null string
comptr null string
emploees 100 int
Indica "MSE" string
indica "MSE" string
isLocked false bool
Journl "60" string
journl "60" string
legalFormId 0 int
LegalFormId 0 int
Locked false bool
mail "D" string
Mail "D" string
Member "2 D" string
member "2 D" string
NoEmpl 100 int
OfficeHr "M-Fr: 9.00-17.00" string
officeHr "M-Fr: 9.00-17.00" string
Origin "IE" string
originCountry "IE" string
printOptions "1P" string
Prtopt "1P" string
RegDate "2001" string
regDate "2001" string
regNo "123456N" string
RegNo "123456N" string
ReplyCodeId 0 int
replyCodeId 0 int
Serial "70950520" string
serial "70950520" string
vatno "" string
VatNo "" string