Using Mybatis - Spring and having a problem with CHAR types

184 views
Skip to first unread message

jlopes151

unread,
Nov 28, 2011, 6:02:47 AM11/28/11
to mybatis-user
I have a test project that access data from a MySQL 5.1 database,
String types are accessed but I get nothing from a CHAR(3). The getter
is called but I get no errors, no data. I looked into TypeHandles but
the manual suggests I shouldn't need to create one.

I'm having the same problems with SQL Server which does throw an error
suggesting a TypeHandler may be needed.

Any suggestion?

Larry Meadors

unread,
Nov 28, 2011, 8:56:09 AM11/28/11
to mybati...@googlegroups.com
Give us something to look at.

jlopes151

unread,
Nov 28, 2011, 10:33:04 AM11/28/11
to mybatis-user
From the begining

The work project makes use of SQL Server, contianing a table with a
column of type char[3], I created a mapper with basic crud, a model
with the column as one of its fields setting the columns field as a
String type.

Straight forward stuff but what I got was an error from SQL Server
that strings or binary data would be truncated since the table only
has the id as an int and all other members are of type String or
char[], and I'm passing int to the id and String to all other fields..
When I mached the char feilds in the model to the table I got the
error from MyBatis that a TypeHandler is needed. Theren't a default
type handler for type char[].

So there really isn't code to look at if there was it would be the
solution code.

> > Any suggestion?- Hide quoted text -
>
> - Show quoted text -

jlopes151

unread,
Nov 28, 2011, 11:46:16 AM11/28/11
to mybatis-user
Ok I put together a Hanlder now I need to wire it in, The iBatis doc
show the creation of sn sqlMap element to the iBatis config. My
project is an myBatis-Spring environment.

> > - Show quoted text -- Hide quoted text -

Richard Yee

unread,
Nov 28, 2011, 11:59:34 AM11/28/11
to mybati...@googlegroups.com
What type are you using for your Char(3) field in Java. You should be able to use a String. If you are using char[3] then that is probably what is causing your error.
 
-Richard

jlopes151

unread,
Nov 29, 2011, 2:38:16 PM11/29/11
to mybatis-user
Ok here's the solution: Fix your typos ;)

Heh I'm working a large project front to back and I missed typed a
field that lead to a SQL Server missleading message, which lead me to
mis the fac that I had already built a mapper that accessed a table
that had char[] feilds. The table I was working has 41 feilds and I
had to back tract each one to find my html was not the problem it was
in my JS. Well I learned a bit about TypeHandlers and to put the
keyboard down when tired.

Thanks for the replies.

Reply all
Reply to author
Forward
0 new messages