Re: Postgresql + booleans = error
Re: Postgresql + booleans = error
- Subject: Re: Postgresql + booleans = error
- From: Lachlan Deck <email@hidden>
- Date: Sat, 18 Feb 2006 12:53:05 +1100
Hi there,
further to the other's suggestions...
On 16/02/2006, at 2:40 AM, Randall Perry wrote:
I used eomodeler to generate the model and EO classes from a
Postgresql db.
I'm having a problem using the boolean data type. If I reference a
boolean
field 'rec.campsiteFri()' like so:
if (rec.campsiteFri()) {
return true;
}
I get a compiler error 'incompatible types'.
Of course you do. For these kinds of Java-based errors you need to
ask yourself:
The return type of campsiteFri() is:
a) a 'boolean'
b) a 'Boolean'
c) a 'Number'
d) a primitive other than 'boolean'
e) some other Object
You answer will have to be anything other than 'a' because in Java
(as opposed to C) 'if' statements must take a 'boolean' primitive
only (or an expression that returns a boolean primitive). Not an int
or even an Object of type Boolean.
I can't use the field in
WOBuilder as it throws a java class cast exception.
WebObjects Builder doesn't throw class cast exceptions. It's a visual
tool only. When you run the application you'd get a class cast
exception because WOConditional expects a Boolean or boolean. Either
is acceptable usually.
That means that your answer above (at the time of writing anyway)
couldn't have been 'b' either...
I've read previous posts saying there are problems using boolean
types in
eomodeler. Should I be avoiding booleans altogether in my db design
and use
integer instead?
Using boolean types should be fine; they work for me. In fact,
whatever types you're working with you should familiarise yourself
with the documentation for EOModeler. Specifically the documentation on
See either of the following...
<file:///Developer/ADC Reference Library/documentation/WebObjects/
UsingEOModeler/index.html>
<http://developer.apple.com/documentation/WebObjects/UsingEOModeler/
index.html>
... and navigate to Working With Attributes >> More About Attribute
Characteristics >> Value Type.
The documentation is quite good.
Here's the eomodeler specs for this field:
ext type val class (java) val type val class prec
------- ---------------- -------- --------- -----
bool Number c NSNumber 1
That should be:
ext type val class (java) val type prec scale
------- ---------------- -------- ---- -----
bool Number c
precision and scale are only relevant for decimal numbers. e.g., 0.234
public class MyEntity extends EOGenericRecord {
...
public Boolean campsiteFri() {
return (Boolean)storedValueForKey("campsiteFri");
}
}
Boolean value;
value = rec.campsiteFri();
if (value != null && value.booleanValue()) {
...
}
Don't forget to test for nulls. Otherwise the next exception you get
will be a NullPointerException.
with regards,
--
Lachlan Deck
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden