are you using the same database when
testing with jboss and websphere. I have not tried this in different environment. But my suggestion is to use an instanceof check and cast it accordingly.
if (object instanceif Integer){
// cast it to Lnteger
}else if (object instanceof Long){
// cast it to Long
}
OR always cast it to Number because both long and integer extend it from Number. and use the appropriate method like longValue() or intValue() from the Number.