« Return to Thread: Mapping GroovyResultSet to POGOs?
The problem was how Oracle treats column aliases. Normally, if you
execute a query like :
select person.first_name name from person ....
the column label will come back as "NAME" -- However, if you
double-quote the label like so:
select person.first_name "name" from person ...
then the label comes back as "name"
Apparently Oracle's ResultSet.getObject( columnName ) accounts for a
difference in case (I think it converts everything to uppercase before
doing any comparison). But since calling toRowResult basically
inspects the ResultSetMetadata and sticks all of the column label :
values into a HashMap (see
http://fisheye.codehaus.org/browse/groovy/trunk/groovy/groovy-core/src/main/groovy/sql/GroovyRowResult.java?r=trunk)
case suddenly matters in that map whose keys are expected to be
case-sensitive property names. Quoting the labels is a little
annoying, but I can't think of a good way to improve toRowResult or
rowResult in a way that could accomodate this. I suppose it's still
easier than having to manually pass each retrieved column value when
constructing my data object.
See also: http://fisheye.codehaus.org/browse/groovy/trunk/groovy/groovy-core/src/main/org/codehaus/groovy/runtime/DefaultGroovyMethods.java?r=16764#l11269
Thanks for the help.
-Tom
On Wed, Jul 1, 2009 at 7:14 PM, Rick<rickcr@...> wrote:
> On Wed, Jul 1, 2009 at 4:24 PM, Tom Nichols <tmnichols@...> wrote:
>>
>> Actually, I just tried this and it didn't quite work as expected. I got
>> groovy.lang.MissingPropertyException: No such property: NAME for class:
>> Person
>>
>> Have you ever encountered that? Apparently the row aliases are being
>> returned as uppercase, even though my query has them in lowercase. It
>> could be vendor-specific (I'm using Oracle) - any ideas there?
>>
>>
>
> hmm just to test if the uppercase is the issue, create a Person class with
> the property NAME (all caps) and see if it works.
>
> (Also, just to double check, make sure all fields returned in your query do
> have matching property definitions in your class, maybe for some weird
> reason it's barfing on 'name' when it's really some other property at the
> root of the problem? - I doubt it, but can't hurt to double check.)
>
>
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
« Return to Thread: Mapping GroovyResultSet to POGOs?
| Free embeddable forum powered by Nabble | Forum Help |