Yes, I think so, and I think that I have to be sorry for my first mail: The code is
NOT 100% ok! I think I found the problem,
please let us all discuss this:
I have a database field that is of type SMALLINT (NULL is allowed). For it is
SMALLINT, best would be to wrap it to a field
of type short in java. But this won't work because short cannot be NULL but only ZERO.
So I need to use a java wrapper like
Integer.
EJBWizard (a bean creation tool specially written for JOnAS and mentioned on the JOnAS
site) does not use Integer but short.
So GenIC find a short and thinks that this can't be NULL and doesn't create code to
look if that fiels is NULL. Instead, it
directly reads the value into the short; if the value is NULL, the short now has a
value of ZERO.
For JOnAS does always write back (I don't know why...) and there is no check if the
entity was modified (CMP: Dirty is always
true; I also don't know why, this is some idea of GenIC...) it now tries to write back
a ZERO where the database wants to
have NULL. For this field has a foreign key constraint on it, SQL now excepts because
the foreign key target does not contain
a row that has a PK that is ZERO. So JOnAS crashes and the transaction gets rolled
back.
Where is the best point to solve the problem?
-> Should EjbWizard be changed? I think it should. It seems to be a clear bug that if
a field may be null that it has to be
wrapped.
-> Should GenIC be changed? I don't think so. For a short cannot be null there is no
need to check for NULLs when reading the
entity.
-> Should JOnAS be changed? I don't think so. It correctly handles all problems.
What do you think about this?
> Would something like:
>
> if (name != null) pstmt.setString(1, name);
> else pstmt.setNull(1, Types.VARCHAR);
>
> Help with your problem?