Inserting Long value into HSQLDB numeric column

16 views
Skip to first unread message

Shannon

unread,
Nov 17, 2010, 5:59:41 PM11/17/10
to mybatis-user
Hello,
I'm trying to insert a Long value (pet_id) into a pet table which has
the ID defined as a NUMERIC(28). When I execute my unit test, I get
the following error:

java.lang.ClassCastException: java.lang.Integer
at $Proxy19.insertPet(Unknown Source)
at
com.petstore.framework.datamanagement.dataaccess.PetDAO.insertRecord(PetDAO.java:
78)
at
com.petstore.framework.datamanagement.dataaccess.mapper.PetDAOMapperTest.insertRecord_Valid(PetDAOMapperTest.java:
123)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
...

the values I am tring to insert: 5, Fido, Bull Dog

I have a pet table, defined as follows:

create table(
pet_id numeric(28),
name varchar(10),
breed varchar(20) );

mapper class:

@Insert( "insert into pet( pet_id, name, breed ) values ( #{ petID,
jdbcType=BIGINT }, #{ name }, #{ breed } )
public void insertPet( @Param("petID") Long petID, @Param("name")
String name, @Param("breed") String breed );

I've also tried different jdbcTypes: NUMERIC and DECIMAL; none seem
to make a difference.

Thanks for your help.

Clinton Begin

unread,
Nov 18, 2010, 12:17:54 AM11/18/10
to mybati...@googlegroups.com
It won't be the JDBC type that's the problem. 

Can you submit a simple unit test that demonstrates the problem?

Cheers,
Clinton

Shannon

unread,
Nov 18, 2010, 12:20:32 PM11/18/10
to mybatis-user
Hi Clinton,
Issue is resolved. It turns out that I have to specify the javaType.
Perhaps this was only required because I'm using an embedded database;
but it works now.

For someone else who may come across this same issue:

@Insert( "insert into pet( pet_id, name, breed ) values ( #{ petID,
javaType=Long, jdbcType=BIGINT }, #{ name }, #{ breed } )
public void insertPet( @Param("petID") Long petID, @Param("name")
String name, @Param("breed") String breed );

Thanks anyways.


On Nov 17, 11:17 pm, Clinton Begin <clinton.be...@gmail.com> wrote:
> It won't be the JDBC type that's the problem.
>
> Can you submit a simple unit test that demonstrates the problem?
>
> Cheers,
> Clinton
>
>
>
> On Wed, Nov 17, 2010 at 3:59 PM, Shannon <liveitha...@gmail.com> wrote:
> > Hello,
> > I'm trying to insert a Long value (pet_id) into a pet table which has
> > the ID defined as a NUMERIC(28).  When I execute my unit test, I get
> > the following error:
>
> > java.lang.ClassCastException:  java.lang.Integer
> >   at $Proxy19.insertPet(Unknown Source)
> >   at
>
> > com.petstore.framework.datamanagement.dataaccess.PetDAO.insertRecord(PetDAO­.java:
> > 78)
> >   at
>
> > com.petstore.framework.datamanagement.dataaccess.mapper.PetDAOMapperTest.in­sertRecord_Valid(PetDAOMapperTest.java:
> > 123)
> >   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >   ...
>
> > the values I am tring to insert:  5, Fido, Bull Dog
>
> > I have a pet table, defined as follows:
>
> > create table(
> >   pet_id numeric(28),
> >   name varchar(10),
> >   breed varchar(20) );
>
> > mapper class:
>
> > @Insert( "insert into pet( pet_id, name, breed ) values ( #{ petID,
> > jdbcType=BIGINT }, #{ name }, #{ breed } )
> > public void insertPet( @Param("petID") Long petID, @Param("name")
> > String name, @Param("breed") String breed );
>
> > I've also tried different jdbcTypes:  NUMERIC and DECIMAL; none seem
> > to make a difference.
>
> > Thanks for your help.- Hide quoted text -
>
> - Show quoted text -

Shannon

unread,
Nov 18, 2010, 12:21:00 PM11/18/10
to mybatis-user
Hi Clinton,
Issue is resolved. It turns out that I have to specify the javaType.
Perhaps this was only required because I'm using an embedded database;
but it works now.

For someone else who may come across this same issue:

@Insert( "insert into pet( pet_id, name, breed ) values ( #{ petID,
javaType=Long, jdbcType=BIGINT }, #{ name }, #{ breed } )
public void insertPet( @Param("petID") Long petID, @Param("name")
String name, @Param("breed") String breed );

Thanks anyways.


On Nov 17, 11:17 pm, Clinton Begin <clinton.be...@gmail.com> wrote:
> It won't be the JDBC type that's the problem.
>
> Can you submit a simple unit test that demonstrates the problem?
>
> Cheers,
> Clinton
>
>
>
> On Wed, Nov 17, 2010 at 3:59 PM, Shannon <liveitha...@gmail.com> wrote:
> > Hello,
> > I'm trying to insert a Long value (pet_id) into a pet table which has
> > the ID defined as a NUMERIC(28).  When I execute my unit test, I get
> > the following error:
>
> > java.lang.ClassCastException:  java.lang.Integer
> >   at $Proxy19.insertPet(Unknown Source)
> >   at
>
> > com.petstore.framework.datamanagement.dataaccess.PetDAO.insertRecord(PetDAO­.java:
> > 78)
> >   at
>
> > com.petstore.framework.datamanagement.dataaccess.mapper.PetDAOMapperTest.in­sertRecord_Valid(PetDAOMapperTest.java:
> > 123)
> >   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> >   ...
>
> > the values I am tring to insert:  5, Fido, Bull Dog
>
> > I have a pet table, defined as follows:
>
> > create table(
> >   pet_id numeric(28),
> >   name varchar(10),
> >   breed varchar(20) );
>
> > mapper class:
>
> > @Insert( "insert into pet( pet_id, name, breed ) values ( #{ petID,
> > jdbcType=BIGINT }, #{ name }, #{ breed } )
> > public void insertPet( @Param("petID") Long petID, @Param("name")
> > String name, @Param("breed") String breed );
>
> > I've also tried different jdbcTypes:  NUMERIC and DECIMAL; none seem
> > to make a difference.
>

Clinton Begin

unread,
Nov 18, 2010, 10:50:19 PM11/18/10
to mybati...@googlegroups.com
Ah, I just noticed your BIGINT jdbcType... yes, that makes sense now, as BIGINT by default would be mapped to a BigDecimal.

Clinton
Reply all
Reply to author
Forward
0 new messages