how to map char(1) to java.lang.Character

84 views
Skip to first unread message

Gregory Kotsaftis

unread,
May 25, 2015, 1:06:30 PM5/25/15
to mybati...@googlegroups.com
Hello,

I have a CHAR(1) field [mytype] accepting some values in a postgresql table like this:

CREATE TABLE tbl_contact (
    contact_id    INTEGER         PRIMARY KEY,
    mytype        CHAR(1)         NOT NULL            CHECK( mytype IN ('E','M','O','P','W') ),
    mydesc        VARCHAR(32)                         CHECK( trim(mydesc) <> '' ),
    myflag        BOOLEAN         NOT NULL
);


Is there a way to map the CHAR(1) field to java.lang.Character?

Guy Rouillier

unread,
May 25, 2015, 8:23:50 PM5/25/15
to mybati...@googlegroups.com
Have you tried it?  Are you getting an error?  I don't see why this wouldn't work.
 
--
Guy Rouillier
--
You received this message because you are subscribed to the Google Groups "mybatis-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mybatis-user...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



Avast logo

This email has been checked for viruses by Avast antivirus software.
www.avast.com


Gregory Kotsaftis

unread,
May 26, 2015, 3:45:32 AM5/26/15
to mybati...@googlegroups.com
Yes, it fails with this exception:

Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in gr/metadata/clinic/db/mybatis/generated/PersonTblMapper.xml
### The error occurred while processing mapper_resultMap[BaseResultMap]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'Character'.  Cause: java.lang.ClassNotFoundException: Cannot find class: Character
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:46)

I have verified it is that field (char(1) mapped to a java.lang.Character). If I change the mapping to String, it works.


From: Guy Rouillier <guy.ro...@gmail.com>
To: mybati...@googlegroups.com; "mybati...@googlegroups.com" <mybati...@googlegroups.com>
Sent: Tuesday, May 26, 2015 3:23 AM
Subject: Re: how to map char(1) to java.lang.Character

Gregory Kotsaftis

unread,
May 26, 2015, 4:03:27 AM5/26/15
to mybati...@googlegroups.com
If i change the mapping from <arg column="gender" jdbcType="CHAR" javaType="Character" /> to <arg column="gender" jdbcType="CHAR" javaType="java.lang.Character" />
I get this exception instead:

Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error building SqlSession.
### The error may exist in gr/metadata/clinic/db/mybatis/generated/PersonTblMapper.xml
### The error occurred while processing mapper_resultMap[BaseResultMap]
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. Cause: java.lang.IllegalStateException: No typehandler found for property null

    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:26)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:54)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:46)


From: 'Gregory Kotsaftis' via mybatis-user <mybati...@googlegroups.com>
To: "mybati...@googlegroups.com" <mybati...@googlegroups.com>
Sent: Tuesday, May 26, 2015 10:42 AM

Subject: Re: how to map char(1) to java.lang.Character

Gregory Kotsaftis

unread,
May 26, 2015, 5:39:32 AM5/26/15
to mybati...@googlegroups.com
it seems that "No typehandler found for property null" was caused by next field that was a java.time.LocalDate.
Luckily i found this project javaplugs/mybatis-java-time and it seems i have no errors any more...
 
 
image
 
 
 
 
 
javaplugs/mybatis-java-time
mybatis-java-time - Java 8 time (JSR 310) support for Mybatis 3.x
Preview by Yahoo
 
 
Reply all
Reply to author
Forward
0 new messages