Hibernate常见异常

1.数据库编码问题

主要错误信息

WARN: SQL Error: 1366, SQLState: 22001 ... ERROR: Data truncation: Incorrect string value: ‘\xE5\xB9\xBF\xE5\xB7\x9E...‘ for column ‘addressDetail‘ at row 1

详细错误

  1 Jan 16, 2017 9:40:30 AM org.hibernate.annotations.common.reflection.java.JavaReflectionManager <clinit>
  2 INFO: HCANN000001: Hibernate Commons Annotations {4.0.5.Final}
  3 Jan 16, 2017 9:40:30 AM org.hibernate.Version logVersion
  4 INFO: HHH000412: Hibernate Core {4.3.11.Final}
  5 Jan 16, 2017 9:40:30 AM org.hibernate.cfg.Environment <clinit>
  6 INFO: HHH000206: hibernate.properties not found
  7 Jan 16, 2017 9:40:30 AM org.hibernate.cfg.Environment buildBytecodeProvider
  8 INFO: HHH000021: Bytecode provider name : javassist
  9 Jan 16, 2017 9:40:30 AM org.hibernate.cfg.Configuration configure
 10 INFO: HHH000043: Configuring from resource: /hibernate.cfg.xml
 11 Jan 16, 2017 9:40:30 AM org.hibernate.cfg.Configuration getConfigurationInputStream
 12 INFO: HHH000040: Configuration resource: /hibernate.cfg.xml
 13 Jan 16, 2017 9:40:31 AM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity
 14 WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
 15 Jan 16, 2017 9:40:31 AM org.hibernate.cfg.Configuration doConfigure
 16 INFO: HHH000041: Configured SessionFactory: null
 17 Jan 16, 2017 9:40:31 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
 18 INFO: HHH010002: C3P0 using driver: com.mysql.jdbc.Driver at URL: jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8
 19 Jan 16, 2017 9:40:31 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
 20 INFO: HHH000046: Connection properties: {user=root, password=****}
 21 Jan 16, 2017 9:40:31 AM org.hibernate.c3p0.internal.C3P0ConnectionProvider configure
 22 INFO: HHH000006: Autocommit mode: false
 23 Jan 16, 2017 9:40:31 AM com.mchange.v2.log.MLog <clinit>
 24 INFO: MLog clients using java 1.4+ standard logging.
 25 Jan 16, 2017 9:40:31 AM com.mchange.v2.c3p0.C3P0Registry banner
 26 INFO: Initializing c3p0-0.9.2.1 [built 20-March-2013 10:47:27 +0000; debug? true; trace: 10]
 27 Jan 16, 2017 9:40:31 AM com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
 28 INFO: Initializing c3p0 pool... [email protected] [ connectionPoolDataSource -> [email protected] [ acquireIncrement -> 2, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1hgeby99l19rgv2u1ixjy4j|-5a89dabc, idleConnectionTestPeriod -> 3000, initialPoolSize -> 1, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 5000, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 20, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 1, nestedDataSource -> [email protected] [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1hgeby99l19rgv2u1ixjy4j|-33394b6a, jdbcUrl -> jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8, properties -> {user=******, password=******} ], preferredTestQuery -> null, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> false, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1hgeby99l19rgv2u1ixjy4j|7826c6fd, numHelperThreads -> 3 ]
 29 Jan 16, 2017 9:40:31 AM org.hibernate.dialect.Dialect <init>
 30 INFO: HHH000400: Using dialect: org.hibernate.dialect.MySQLDialect
 31 Jan 16, 2017 9:40:31 AM org.hibernate.engine.jdbc.internal.LobCreatorBuilder useContextualLobCreation
 32 INFO: HHH000424: Disabling contextual LOB creation as createClob() method threw error : java.lang.reflect.InvocationTargetException
 33 Jan 16, 2017 9:40:32 AM org.hibernate.engine.transaction.internal.TransactionFactoryInitiator initiateService
 34 INFO: HHH000399: Using default transaction strategy (direct JDBC transactions)
 35 Jan 16, 2017 9:40:32 AM org.hibernate.hql.internal.ast.ASTQueryTranslatorFactory <init>
 36 INFO: HHH000397: Using ASTQueryTranslatorFactory
 37 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
 38 INFO: HHH000228: Running hbm2ddl schema update
 39 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
 40 INFO: HHH000102: Fetching database metadata
 41 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
 42 INFO: HHH000396: Updating schema
 43 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 44 INFO: HHH000262: Table not found: address_inf
 45 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 46 INFO: HHH000262: Table not found: person_address
 47 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 48 INFO: HHH000262: Table not found: person_inf
 49 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 50 INFO: HHH000262: Table not found: address_inf
 51 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 52 INFO: HHH000262: Table not found: person_address
 53 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 54 INFO: HHH000262: Table not found: person_inf
 55 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 56 INFO: HHH000262: Table not found: address_inf
 57 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 58 INFO: HHH000262: Table not found: person_address
 59 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.DatabaseMetadata getTableMetadata
 60 INFO: HHH000262: Table not found: person_inf
 61 Jan 16, 2017 9:40:32 AM org.hibernate.tool.hbm2ddl.SchemaUpdate execute
 62 INFO: HHH000232: Schema update complete
 63 Hibernate: insert into person_inf (age, name) values (?, ?)
 64 Hibernate: insert into address_inf (addressDetail) values (?)
 65 Jan 16, 2017 9:40:32 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 66 WARN: SQL Error: 1366, SQLState: 22001
 67 Jan 16, 2017 9:40:32 AM org.hibernate.engine.jdbc.spi.SqlExceptionHelper logExceptions
 68 ERROR: Data truncation: Incorrect string value: ‘\xE5\xB9\xBF\xE5\xB7\x9E...‘ for column ‘addressDetail‘ at row 1
 69 Exception in thread "main" org.hibernate.exception.DataException: could not execute statement
 70     at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:69)
 71     at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)
 72     at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:126)
 73     at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:112)
 74     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:211)
 75     at org.hibernate.id.IdentityGenerator$GetGeneratedKeysDelegate.executeAndExtract(IdentityGenerator.java:96)
 76     at org.hibernate.id.insert.AbstractReturningDelegate.performInsert(AbstractReturningDelegate.java:58)
 77     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3032)
 78     at org.hibernate.persister.entity.AbstractEntityPersister.insert(AbstractEntityPersister.java:3558)
 79     at org.hibernate.action.internal.EntityIdentityInsertAction.execute(EntityIdentityInsertAction.java:98)
 80     at org.hibernate.engine.spi.ActionQueue.execute(ActionQueue.java:492)
 81     at org.hibernate.engine.spi.ActionQueue.addResolvedEntityInsertAction(ActionQueue.java:197)
 82     at org.hibernate.engine.spi.ActionQueue.addInsertAction(ActionQueue.java:181)
 83     at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:216)
 84     at org.hibernate.event.internal.AbstractSaveEventListener.addInsertAction(AbstractSaveEventListener.java:334)
 85     at org.hibernate.event.internal.AbstractSaveEventListener.performSaveOrReplicate(AbstractSaveEventListener.java:289)
 86     at org.hibernate.event.internal.AbstractSaveEventListener.performSave(AbstractSaveEventListener.java:195)
 87     at org.hibernate.event.internal.AbstractSaveEventListener.saveWithGeneratedId(AbstractSaveEventListener.java:126)
 88     at org.hibernate.event.internal.DefaultPersistEventListener.entityIsTransient(DefaultPersistEventListener.java:206)
 89     at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:149)
 90     at org.hibernate.event.internal.DefaultPersistEventListener.onPersist(DefaultPersistEventListener.java:75)
 91     at org.hibernate.internal.SessionImpl.firePersist(SessionImpl.java:811)
 92     at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:784)
 93     at org.hibernate.internal.SessionImpl.persist(SessionImpl.java:789)
 94     at hql.PersonManager.testPerson(PersonManager.java:45)
 95     at hql.PersonManager.main(PersonManager.java:21)
 96 Caused by: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Incorrect string value: ‘\xE5\xB9\xBF\xE5\xB7\x9E...‘ for column ‘addressDetail‘ at row 1
 97     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4118)
 98     at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:4052)
 99     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:2503)
100     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2664)
101     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2794)
102     at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2155)
103     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2458)
104     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2375)
105     at com.mysql.jdbc.PreparedStatement.executeUpdate(PreparedStatement.java:2359)
106     at com.mchange.v2.c3p0.impl.NewProxyPreparedStatement.executeUpdate(NewProxyPreparedStatement.java:147)
107     at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.executeUpdate(ResultSetReturnImpl.java:208)
108     ... 21 more

错误原因及解决办法

这种问题通常都是因为你的数据库或者表的编码不支持中文,查看mysql中数据库和表的属性就知道,

可以看到当前的编码是拉丁文的,我们需要改为 utf8-general-ci 编码,

当然数据表也需要重建或修改编码,因为之前建的数据表也跟数据库的编码一样了,现在也要改为 utf8-general-ci

之后Hibernate就可以正常工作啦  ^_^

 

时间: 2024-10-09 16:04:45

Hibernate常见异常的相关文章

Hibernate 常见异常

Hibernate 常见异常net.sf.hibernate.MappingException        当出现net.sf.hibernate.MappingException: Error reading resource:…异常时一般是因为映射文件出现错误. 当出现net.sf.hibernate.MappingException: Resource: … not found是因为XML配置文件没找到所致,有可能是放置目录不正确,或者没将其加入hibernate.cfg.xml中. 2

spring+hibernate常见异常集合

spring+hibernate出错小结: (1)java.lang.NoClassDefFoundError: org/hibernate/context/CurrentSessionContext 原因:出现这错误时,请更改hibernate的包,更新至最新或3.1以上 (2)java.lang.NoClassDefFoundError: javax/transaction/TransactionManager 原因:缺少jta.jar 或者是找不到hbm.xml文件导致sessionfac

开发常见异常

常见异常总结: 问题:IllegalAgumentExecption 问题:内存溢出异常 这个一般报[http-8080-3]之类的 1.在eclipse安装目录中将eclipse的启动参数调大一些: -startup plugins/org.eclipse.equinox.launcher_1.3.100.v20150511-1540.jar --launcher.library plugins/org.eclipse.equinox.launcher.win32.win32.x86_64_1

Maven常见异常解决《二》

下面是一些Maven工程的常见异常:   1.ReasonPhrase: Forbidden: |--- 1.注意用户的权限以及角色role的设置,通常是没有权限才会被禁止的. 2.Failed to collect dependencies: |--- 1.须要把parentproject,也就是package是pom的那个project先install一下.或者deploy |--- 2.须要注意在设置的<profile>工厂里面能否够訪问,假设直接訪问public分组,那么就要检查pub

Maven常见异常及解决方法(本篇停更至16-4-12)

本篇文章记录了老猫在学习整合Maven和SSH过程中遇到的问题,有的问题可以解决.有的问题还不能解决. 方法不一定适合全部的环境.但绝对是本人常遇到的常见异常.在这里做一个笔记和记录,也分享给大家,希望大家多多给出见解. 假设有不同的见解,请依照编号写出自己的见解吧,老猫愿闻其详! 此文老猫原创.转载请加本文连接:http://blog.csdn.net/nthack5730/article/details/46633287 很多其它有关老猫的文章:http://blog.csdn.net/nt

Hibernate常见错误整理

Hibernate常见错误合集 1.错误:object references an unsaved transient instance - save the transient instance before flushing: com.xxxx.bean.java.Sysblog; nested exception is org.hibernate.TransientObjectException: object references an unsaved transient instanc

2015-09-16 mysql 主从原理、 同步常见异常及恢复方法

1.原理 MySQL复制技术有以下一些特点:            (1)    数据分布 (Data distribution ) (2)    负载平衡(load balancing)             (3)    备份(Backups)           (4)    高可用性和容错行 High availability and failover 整体上来说,复制有3个步骤: (1)    master将改变记录到二进制日志(binary log)中(这些记录叫做二进制日志事件,

Hadoop常见异常及其解决方案

1.Shell$ExitCodeException 现象:运行hadoop job时出现如下异常: 14/07/09 14:42:50 INFO mapreduce.Job: Task Id : attempt_1404886826875_0007_m_000000_1, Status : FAILED Exception from container-launch: org.apache.hadoop.util.Shell$ExitCodeException: org.apache.hadoo

开通博客第一天 (先发一些android(java)常见异常信息

常见异常: java.lang.AbstractMethodError抽象方法错误.当应用试图调用抽象方法时抛出. java.lang.AssertionError断言错.用来指示一个断言失败的情况. java.lang.ClassCircularityError类循环依赖错误.在初始化一个类时,若检测到类之间循环依赖则抛出该异常. java.lang.ClassFormatError类格式错误.当Java虚拟机试图从一个文件中读取Java类,而检测到该文件的内容不符合类的有效格式时抛出. ja