Send us your mapper interface method.
Richard
Sent from my iPhone
To recap what generates the null pointer exception when inserting:
My bean:
public class Game extends SkBean {
private long id;
private Long jackpotid = null; //////////////////
<<<<<<<<<<<<<<< this is the one Im trying to insert null!!!!!
:
Other fields and getters and setters
:
mapper.xml:
<insert id="insert">
<selectKey resultType="long" order="BEFORE" keyProperty="id">select
gameseq.nextval as value from dual</selectKey>
insert into game ( id, jackpotid)
values ( #{id, javaType=long},
#{jackpotid, javaType=Long,
jdbcType=BIGINT} <!-------------- LOOK IM SETTING THE JAVA TYPE --->
)
</insert>
Oracle Table:
CREATE TABLE SK_ENGINE.GAME
(
ID INTEGER NOT NULL
,JACKPOTID
INTEGER <<<<<<<<<<<<<
The table field is nullable
)
The mapper interface is like this:
public interface GameMapper {
Integer insert(Game game);
}
Im calling the mapper like this:
Game game = new Game();
SqlSession sqlSession = SqlSessionFactory.getFactory().openSession();
try {
Mapper mapper = sqlSession.getMapper(UserMapper.class);
mapper.insert(game);
} finally {
sqlSesssion.close();
I can insert fine as long as all the bean fields are not null, any
null ones blow up, even if the jdbcType is set.
Has anyone found a way round this? Is it possible to intercept the
SQL and injesct setNull() into the prepared statements or similar?
Does anyone have one single working example which can insert nulls
into the db I can have a look at?
This is the null pointer error:
Simon.
Richard
Sent from my iPhone
> org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
> 8)
> at
> org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:
> 100)
> at
> org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:
For now, I have made the columns on all my tables not null, and am
using -1 and "" to represent null instead of null. I haven't got a
strategy for dealing with psudo null dates yet - I might have to write
two versions of inserts, one with the date column and one without.
Or investigate the dynamic sql, although all the examples with nulls
are for the where clause of a select, so not sure if this would work
inside an insert.
Simon.
Richard
Sent from my iPhone
> 8)
> at
> org
> .apache
> .ibatis
> .session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:
> 100)
> at
> org
> .apache
> .ibatis
> .session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:
org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:
8)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:
100)
at
org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java: