org.hibernate.exception.GenericJDBCException: could not execute statement

今天在学习Hibernate时,运行简单的测试类报如下错误:

Hibernate: 
    insert 
    into
        cst_name
        (lkm_name, lkm_gender, lkm_phone, lkm_mobile, lkm_email, lkm_qq, lkm_position, lkm_memo, lkm_cust_id) 
    values
        (?, ?, ?, ?, ?, ?, ?, ?, ?)
20:20:45,695  WARN SqlExceptionHelper:127 - SQL Error: 1366, SQLState: HY000
20:20:45,696 ERROR SqlExceptionHelper:129 - Incorrect string value: '\xE5\x87\xA4\xE5\xA7\x90' for column 'lkm_name' at row 1
Exception in thread "main" org.hibernate.exception.GenericJDBCException: could not execute statement
 at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:47)
 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:109)
 at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:95)
 at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:207)
 at org.hibernate.dialect.identity.GetGeneratedKeysDelegate.executeAndExtract(GetGeneratedKeysDelegate.java:57)
 at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:42)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:2792)
 at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3363)
 at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:81)
 at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:597)
 at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:232)
 at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:213)
 at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:256)
 at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:317)
 at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:272)
 at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:178)
 at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:109)
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.saveWithGeneratedOrRequestedId(DefaultSaveOrUpdateEventListener.java:192)
 at org.hibernate.event.internal.DefaultSaveEventListener.saveWithGeneratedOrRequestedId(DefaultSaveEventListener.java:38)
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.entityIsTransient(DefaultSaveOrUpdateEventListener.java:177)
 at org.hibernate.event.internal.DefaultSaveEventListener.performSaveOrUpdate(DefaultSaveEventListener.java:32)
 at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:73)
 at org.hibernate.internal.SessionImpl.fireSave(SessionImpl.java:679)
 at org.hibernate.internal.SessionImpl.save(SessionImpl.java:671)
 at org.hibernate.internal.SessionImpl.save(SessionImpl.java:666)
 at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
 at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
 at java.lang.reflect.Method.invoke(Unknown Source)
 at org.hibernate.context.internal.ThreadLocalSessionContext$TransactionProtectionWrapper.invoke(ThreadLocalSessionContext.java:338)
 at com.sun.proxy.$Proxy24.save(Unknown Source)
 at com.itheima.hibernate.demo1.HibernateDemo1.main(HibernateDemo1.java:46)

根据报错的提示,
20:20:45,696 ERROR SqlExceptionHelper:129 - Incorrect string value: '\xE5\x87\xA4\xE5\xA7\x90' for column 'lkm_name' at row 1我去找了找跟lkm_name有关的地方,找来找去发现实体类没错,那剩下的就是配置文件,在映射时可能出错了,最后发现,是数据库表名没写对。lkm_name是第一列,所以这一列会报错,将报名改对就OK了。

你可能感兴趣的:(学习笔记,经验分享)