Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » ObjectTypeConverter problems
ObjectTypeConverter problems [message #385448] Sat, 07 February 2009 21:34 Go to next message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 136
Registered: July 2009
Senior Member
using EclipseLink 1.0.2, Oracle 10.2


Hi,

Would anybody know why this converter annotation doesn't work (always
returning false for null values)? The field is a nullable VARCHAR2(1).
The possible values for the field should be "Y" or NULL, mapping to
true, or "N" for false.

@Column(name = "INACTIVE_IND")
@ObjectTypeConverter(
name="booleanConverter_N-false",
dataType=java.lang.String.class,
objectType=java.lang.Boolean.class,
conversionValues={
@ConversionValue(dataValue="N", objectValue="false")
},
defaultObjectValue="true")
@Convert("booleanConverter_N-false")
private boolean active;


.... while this one (on different entity with the same field definition,
though using 0 for false and 1/NULL for true) does?

@Column(name = "INACTIVE_IND")
@ObjectTypeConverter(
name="booleanConverter_0-false",
dataType=java.lang.String.class,
objectType=java.lang.Boolean.class,
conversionValues={
@ConversionValue(dataValue="0", objectValue="false")
},
defaultObjectValue="true")
@Convert("booleanConverter_0-false")
private boolean active;


I have several converter annotations working for similar boolean
conversions on other entities, both for null and non-null values. Both
the one that's failing and the one below it operate on materialized
views, so that can't be the problem. The only difference between the
views is that currently all of the "INACTIVE_IND" values for the problem
view are NULL.

If I change the field to use a Boolean type wrapper, I get an NPE for
null values.

I then wrote a Converter impl to do the same thing as a sanity check,
and it works fine:

public class BooleanConverter_N_false
implements Converter
{
public Object convertDataValueToObjectValue(
Object dataValue,
Session session)
{
return ((dataValue != null) && dataValue.equals("N")) ?
Boolean.FALSE :
Boolean.TRUE;
}


public Object convertObjectValueToDataValue(
Object objectValue,
Session session)
{
return (objectValue == Boolean.FALSE) ?
"N" :
null;
}


public void initialize(DatabaseMapping mapping, Session session)
{
}


public boolean isMutable()
{
return false;
}
}


This Converter impl will get me by fine, but I'm still baffled. Any ideas?

Thanks,
Ari
Re: ObjectTypeConverter problems [message #385449 is a reply to message #385448] Mon, 09 February 2009 15:43 Go to previous messageGo to next message
James Sutherland is currently offline James SutherlandFriend
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

This is occurring as the ObjectTypeConverter has special handling for null
values.

The defaultObjectValue does not handle null values. But perhaps it should
so feel free to log a bug for this. "defaultObjectValue" is only for if
you have legacy data that has other values than you have set, and want to
default these. The mapping has a nullValue that can be set for the value
for null, but there does not seem to be a way to set this through
annotations (please log a bug), you can set it using a
DescriptorCustomizer.
For null, the converter allows the conversion value for null to be set,
i.e. null=true, but there does not seem to be a way to set null through
annotations, maybe log a bug for this. You can set the conversion for
null in code.

In your converter you must translate each value, so you need to give the
value for "Y"="true", other if you write out true, you will not get "Y" in
the database.

---
James
http://www.nabble.com/EclipseLink---Users-f26658.html


James : Wiki : Book : Blog : Twitter
Re: ObjectTypeConverter problems [message #385452 is a reply to message #385449] Tue, 10 February 2009 22:04 Go to previous messageGo to next message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 136
Registered: July 2009
Senior Member
Thanks a lot James -- restored my sanity. ;-) I confirmed that the one
other case I had with NULL values was one where
defaultObjectValue="false", so it just *happened* to show as correct in
my tests. When I changed it to defaultObjectValue="true" as a test, it
still returned false, confirming that the ObjectTypeConverter is not
handling it.

Regarding my converter code, my client preferred to see NULL for true
rather than "Y", which is why I had it like that (the data objects
happen to be views anyway, so they won't be written to).

I'll log a bug for this, and in the meantime switch to using custom
converters.

It would be nice if the Wiki were updated about this, since it says:

http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_the_.40ObjectTypeConverter_Annotation
defaultObjectValue: Set the value of this attribute to the default
object value. Note that this argument is for dealing with legacy data if
the data value is missing.

I assumed this meant it was specifically meant for NULL ("missing")
values, but from what you said this is definitely not the case.

Thanks,
Ari

James wrote:
> This is occurring as the ObjectTypeConverter has special handling for
> null values.
>
> The defaultObjectValue does not handle null values. But perhaps it
> should so feel free to log a bug for this. "defaultObjectValue" is only
> for if you have legacy data that has other values than you have set, and
> want to default these. The mapping has a nullValue that can be set for
> the value for null, but there does not seem to be a way to set this
> through annotations (please log a bug), you can set it using a
> DescriptorCustomizer.
> For null, the converter allows the conversion value for null to be set,
> i.e. null=true, but there does not seem to be a way to set null through
> annotations, maybe log a bug for this. You can set the conversion for
> null in code.
>
> In your converter you must translate each value, so you need to give the
> value for "Y"="true", other if you write out true, you will not get "Y"
> in the database.
>
> ---
> James
> http://www.nabble.com/EclipseLink---Users-f26658.html
>
Re: ObjectTypeConverter problems [message #385743 is a reply to message #385452] Thu, 26 February 2009 21:48 Go to previous message
Ari Meyer is currently offline Ari MeyerFriend
Messages: 136
Registered: July 2009
Senior Member
Bug logged and will be addressed for 1.1:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=265597


Ari Meyer wrote:
> Thanks a lot James -- restored my sanity. ;-) I confirmed that the one
> other case I had with NULL values was one where
> defaultObjectValue="false", so it just *happened* to show as correct in
> my tests. When I changed it to defaultObjectValue="true" as a test, it
> still returned false, confirming that the ObjectTypeConverter is not
> handling it.
>
> Regarding my converter code, my client preferred to see NULL for true
> rather than "Y", which is why I had it like that (the data objects
> happen to be views anyway, so they won't be written to).
>
> I'll log a bug for this, and in the meantime switch to using custom
> converters.
>
> It would be nice if the Wiki were updated about this, since it says:
>
> http://wiki.eclipse.org/Using_EclipseLink_JPA_Extensions_(ELUG)#How_to_Use_the_.40ObjectTypeConverter_Annotation
>
> defaultObjectValue: Set the value of this attribute to the default
> object value. Note that this argument is for dealing with legacy data if
> the data value is missing.
>
> I assumed this meant it was specifically meant for NULL ("missing")
> values, but from what you said this is definitely not the case.
>
> Thanks,
> Ari
>
> James wrote:
>> This is occurring as the ObjectTypeConverter has special handling for
>> null values.
>>
>> The defaultObjectValue does not handle null values. But perhaps it
>> should so feel free to log a bug for this. "defaultObjectValue" is
>> only for if you have legacy data that has other values than you have
>> set, and want to default these. The mapping has a nullValue that can
>> be set for the value for null, but there does not seem to be a way to
>> set this through annotations (please log a bug), you can set it using
>> a DescriptorCustomizer.
>> For null, the converter allows the conversion value for null to be
>> set, i.e. null=true, but there does not seem to be a way to set null
>> through annotations, maybe log a bug for this. You can set the
>> conversion for null in code.
>>
>> In your converter you must translate each value, so you need to give
>> the value for "Y"="true", other if you write out true, you will not
>> get "Y" in the database.
>>
>> ---
>> James
>> http://www.nabble.com/EclipseLink---Users-f26658.html
>>
Previous Topic:ClassNotFoundException when configuring caching in OSGi environment
Next Topic:most optimal wy to persisted list?
Goto Forum:
  


Current Time: Thu Apr 18 07:44:15 GMT 2024

Powered by FUDForum. Page generated in 0.02298 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top