Re: EOModelPrototype CastClass Exception
Re: EOModelPrototype CastClass Exception
- Subject: Re: EOModelPrototype CastClass Exception
- From: James Cicenia <email@hidden>
- Date: Sat, 18 Dec 2004 13:21:04 -0600
Hmm..
I figured out that it has to do with TINYINT in mySQL. I think the
solution is to change it to INT.
mySQL seems to return something that I can't figure out how to cast
when it is a TINYINT
On Dec 18, 2004, at 12:57 PM, MacFirst wrote:
on 12/18/04 9:49 AM, Kieran Kelleher <email@hidden> went on
and
on saying, in part:
On Dec 18, 2004, at 11:44 AM, James Cicenia wrote:
I have an eogenerator template that creates code for Booleans:
public Boolean canAdminSite() {
return new
Boolean(((Integer)storedValueForKey("canAdminSite")).intValue()==1);
}
And my eomodel states:
ValueClass = Number
ExternalType = INT
ValueType = i
ValueClass = NSNumber
Why would the above code cause a class cast exception?
Sometimes breaking up a complex statement into simpler ones can help
figure out what's going wrong. Try something like this:
[rewrite of routine, snipped
A good technique but, if you're interested in why the original went
wrong,
try breaking IT into smaller chunks, without rewriting it. Vis:
public Boolean canAdminsite() {
Integer storedValue = (Integer) storedValueForKey
("canAdminSite");
int iStoredValue = storedValue.intValue();
boolean boo = (iStoredValue == 1);
Boolean result = new Boolean (boo);
return (result);
}
Then, one at a time, substitute longer things back in for your
intermediate
values. Although... Looking at it, I don't see anything wrong with
yours.
The only thing I can see that you're missing is check if the stored
value is
null. I typically use something like:
public boolean canAdminSite()
{
return (canAdminSiteBool() != null
&& canAdminSiteBool().intValue() == 1);
}
(canAdminSiteBool() is the stored value in the model.)
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
email@hidden
This email sent to email@hidden
_______________________________________________
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