You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@cayenne.apache.org by Øyvind Harboe <oy...@zylin.com> on 2006/05/20 19:17:23 UTC

Bogus hollow object exception

I'm having a problem with a legacy database that have string primary
keys where there occasionally are extra spaces after the primary key.

SQL will ignore trailing spaces in WHERE clauses, i.e. WHERE
"FOO"="FOO<SPACE>" will yield a match, so this works in the
legacy application I'm porting.

However, Cayenne throws a bogus hollow objection exception.

I managed to find a workaround where I trimmed spaces from primary keys
passed into the ObjectId constructor.

See my working notes & patch at the end:


http://issues.apache.org/cayenne/browse/CAY-550
-- 
Øyvind Harboe
http://www.zylin.com


Re: Bogus hollow object exception

Posted by Øyvind Harboe <oy...@zylin.com>.
On Sat, 2006-05-20 at 16:11 -0400, Andrus Adamchik wrote:
> Could you possibly submit patch (attach it to CAY-550) with a unit  
> test that demonstrates the problem - I'll run it on SQLServer.

I've written up and attached the test case to CAY-550.

However, I've tried half a dozen different combinations to trick
Cayenne into  writing an extranous space into the reference to
TreatAreaspec in the Treatment record, but Cayenne has various smarts to
catch this sort of silly behaviour.

Once I've got this problem sorted, I expect HSQLDB to reproduce the
problem I'm seing.


-- 
Øyvind Harboe
http://www.zylin.com


Re: Bogus hollow object exception

Posted by Andrus Adamchik <an...@objectstyle.org>.
Could you possibly submit patch (attach it to CAY-550) with a unit  
test that demonstrates the problem - I'll run it on SQLServer.

Andrus

On May 20, 2006, at 3:45 PM, Øyvind Harboe wrote:

> On Sat, 2006-05-20 at 13:34 -0400, Andrus Adamchik wrote:
>> Other adapters address trailing space problem by some combination of
>> a trimming CharType and TrimmingQualifierTranslator (see
>> SybaseAdapter and SQLServerAdapter):
>
> I see this problem w/MS SQL server as well as MS Access. I suspect the
> same problem exists with all database types and further that this
> problem has nothing to do with trimming trailing space of database
> fields.
>
> The primary key is a VARCHAR, so I believe that Cayenne is correctly
> translating the VARCHAR to have a trailing space.
>
> The primary key(VARCHAR) in my case is stored *without* the trailing
> space. The reference to the primary key in other tables sometimes
> have a trailing space which is where the trouble starts since WHERE
> "foo"="foo<SPACE>"  will yield a match, whereas ObjectId will not  
> yield
> a match in this case.
>
>> From my limited understanding of the finer points of Cayenne & SQL, I
> can arrive at no other conclusion than that ObjectId's concept of
> equality should match that of SQL's concept of equality in a WHERE
> clause.
>
>
>
>
> -- 
> Øyvind Harboe
> http://www.zylin.com
>
>


Re: Bogus hollow object exception

Posted by Øyvind Harboe <oy...@zylin.com>.
On Sat, 2006-05-20 at 13:34 -0400, Andrus Adamchik wrote:
> Other adapters address trailing space problem by some combination of  
> a trimming CharType and TrimmingQualifierTranslator (see  
> SybaseAdapter and SQLServerAdapter):

I see this problem w/MS SQL server as well as MS Access. I suspect the
same problem exists with all database types and further that this
problem has nothing to do with trimming trailing space of database
fields.

The primary key is a VARCHAR, so I believe that Cayenne is correctly
translating the VARCHAR to have a trailing space.

The primary key(VARCHAR) in my case is stored *without* the trailing
space. The reference to the primary key in other tables sometimes
have a trailing space which is where the trouble starts since WHERE
"foo"="foo<SPACE>"  will yield a match, whereas ObjectId will not yield
a match in this case. 

>>From my limited understanding of the finer points of Cayenne & SQL, I
can arrive at no other conclusion than that ObjectId's concept of
equality should match that of SQL's concept of equality in a WHERE
clause. 




-- 
Øyvind Harboe
http://www.zylin.com


Re: Bogus hollow object exception

Posted by Andrus Adamchik <an...@objectstyle.org>.
Other adapters address trailing space problem by some combination of  
a trimming CharType and TrimmingQualifierTranslator (see  
SybaseAdapter and SQLServerAdapter):


map.registerType(new CharType(true, false));


public QualifierTranslator getQualifierTranslator(QueryAssembler  
queryAssembler) {
         return new TrimmingQualifierTranslator(
                 queryAssembler,
                 SQLServerAdapter.TRIM_FUNCTION);
}

This would be a more generic solution based on things already in  
Cayenne. I think it may fix your case as well.

Andrus


On May 20, 2006, at 1:17 PM, Øyvind Harboe wrote:

> I'm having a problem with a legacy database that have string primary
> keys where there occasionally are extra spaces after the primary key.
>
> SQL will ignore trailing spaces in WHERE clauses, i.e. WHERE
> "FOO"="FOO<SPACE>" will yield a match, so this works in the
> legacy application I'm porting.
>
> However, Cayenne throws a bogus hollow objection exception.
>
> I managed to find a workaround where I trimmed spaces from primary  
> keys
> passed into the ObjectId constructor.
>
> See my working notes & patch at the end:
>
>
> http://issues.apache.org/cayenne/browse/CAY-550
> -- 
> Øyvind Harboe
> http://www.zylin.com
>
>