Hibernate異常總結

1.org.hibernate.exception.ConstraintViolationException: Could not execute JDBC batch update
2.java.lang.OutOfMemoryError: PermGen space(全稱:Permanent Generation space),指的是內存的永久保存區域
3.org.hibernate.hql.ast.QuerySyntaxException
4.Caused by: org.hibernate.ObjectNotFoundException: No row with the given identifier exists: [com.butterfly.entity.Notice#2]
5.Caused by: org.hibernate.exception.SQLGrammarException: could not insert: [com.butterfly.entity.Photo]
6.org.apache.jasper.JasperException: /zone/edit_forum.jsp(2,0) Page directive must not have multiple occurrences of pageencoding
7.Caused by:java.sql.BatchUpdateException: Incorrect string value: '\xE6\x88\x91\xE7\x9A\x84...' for column 'description' at row 1:原因不是主鍵是組合造成了insert和update的誤判,而是mysql裏數據庫
'description' 字段編碼設置的問題,改成utf-8就沒事啦,
8.Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder;問題解決:導入spring包下目錄spring-framework-2.5.6\lib\slf4j的slf4j-log4j12-1.5.0.jar
9.Caused by: java.lang.NoClassDefFoundError: javax/persistence/Entity;缺少ejb3-persistence.jar引起
10.Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.AnnotationConfiguration:缺少hibernate-commons-annotations.jar引起
11.Caused by: java.lang.IllegalArgumentException: 'sessionFactory' or 'hibernateTemplate' is required
  問題是:使用HibernateDaoSupport引起,程序中所有的DAO繼承HibernateDaoSupport,而HibernateDaoSupport需要spring注入'sessionFactory'
12.java.lang.NullPointerException
at org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49):解決辦法是:action裏對應的屬性忘記用@Resource(name="forumCategoryInfor")注入了,寫上問題解決
13.java.lang.OutOfMemoryError: Java heap space
14.org.springframework.dao.InvalidDataAccessApiUsageException: Write operations are not allowed in read-only mode (FlushMode.NEVER/MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.解決:問題是我們開啓了OpenSessionInViewFilter過濾器,配置配置OpenSessionInViewFilter,防止在hibernate延遲加載時,不會再因爲session被關閉,而導致的的延遲加載數據異常 ,這個過濾器的FLUSHMODE默認設置是MANUAL,如果將FLUSHMODE設置爲MANUAL或NEVEL,在操作過程中hibernate會將事務設置爲readOnly,所以刪除,添加就會出現這個異常
15.Caused by: org.hibernate.MappingException: Repeated column in mapping for entity: com.ao.model.Employee column: DEPARTID (should be mapped with insert="false" update="false");
   問題解決:   
    把not-null="true"去掉即可,我數據庫裏設置的是可以爲空,與配置文件的不爲空而引起的
16.java.lang.ClassNotFoundException: org.apache.commons.lang.xwork.StringUtils
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)
 at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)
 at org.apache.struts2.json.SerializationParams.(SerializationParams.java:57)
 at org.apache.struts2.json.JSONResult.writeToResponse(JSONResult.java:214)
 at org.apache.struts2.json.JSONResult.execute(JSONResult.java:204)   解決方案:是由於在struts中使用json缺少jar引起,引入xwork-core-2.1.6.jar即可
17.org.hibernate.QueryException: could not resolve property: employee.depart.departid of: com.ao.model.Hols
18.jboss部署項目:org.jboss.deployers.spi.DeploymentException: URL file:/E:/jboss/jboss-5.0.1.GA/server/default/deploy/study-bbs.war/ deployment failed
  發現deploy下已經存在一個ROOT.war的文件夾,將這個WAR文件刪除掉,重新部署你的包,重啓JBOSS,方解決了

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章