异常如下:
Hibernate: insert into logistics_member_express (create_date, modify_date, address, age, date_of_birth, expr_del_com_id, express_user_id, full_name, gender, id_card, msisdn, nick_name, password, photo, user_name, user_type, id) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) 2015-02-02 20:58:44,437 [http-bio-8000-exec-3] WARN [org.hibernate.util.JDBCExceptionReporter] - SQL Error: 1366, SQLState: HY000 2015-02-02 20:58:44,438 [http-bio-8000-exec-3] ERROR [org.hibernate.util.JDBCExceptionReporter] - Incorrect string value: '\xE7\x94\xB7' for column 'gender' at row 1 2015-02-02 20:58:44,439 [http-bio-8000-exec-3] ERROR [org.hibernate.event.def.AbstractFlushingEventListener] - Could not synchronize database state with session org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140)
在网上查询,参考以链接:
http://www.cnblogs.com/codeplus/archive/2011/08/02/2125546.html
发现是建表时未指定默认的字符集,导致表的字符集是默认的latin1导致,由于是开发环境,数据不重要,所以参照文章说的,删除表再重建表并指定字符集即可,如下:
CREATE TABLE logistics_express_user( id VARCHAR(32) NOT NULL, kuaidi_number VARCHAR(64), sincerity VARCHAR(32), deliver_goods VARCHAR(2560), good_rate DECIMAL(3, 0), create_date DATETIME, modify_date DATETIME, company_name VARCHAR(64) )ENGINE=INNODB DEFAULT CHARSET=UTF8 COMMENT='快递人员专属信息' ;
其中的
DEFAULT CHARSET=UTF8
即指定字符集为utf8