1. 程式人生 > >使用SSH框架遇到的錯誤總結

使用SSH框架遇到的錯誤總結

frame lex utf name ssi 主鍵生成器 color factory creating

1、org.hibernate.exception.ConstraintViolationException: could not insert:

如果是主鍵是自增序列,映射文件 指定主鍵生成器<generator class="native" />

如果是自定義主鍵 <generator class="assigned" />

解決:http://blog.csdn.net/zml_2015/article/details/50282013

2、No Hibernate Session bound to thread

解決辦法是通過註解給service加上事務即可:@Transactional

解決:http://www.myexception.cn/software-architecture-design/904025.html

3、struts配置 result跳出iframe 進入父頁面

設置一個中間頁面 跳進父頁面

解決:http://blog.sina.com.cn/s/blog_a72f208a01014gha.html

4、錯誤 org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘sessionFactory‘ defined in class path resource [config/bean-base.xml]: Invocation of init method failed; nested exception is org.hibernate.InvalidMappingException: Unable to read XML

解決:將<?xml version="1.0" encoding="utf-8"?>

<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"

"http://www.hibernate.org/dtd/hibernate-mapping-3.0.dtd ">的dtd後面的空格去掉

5、報錯:java.lang.NoSuchMethodException: UserAction.delete()

明明action中有方法,卻報錯沒有這個方法。發現方法名有警告,黃色波浪線標記,所以重新寫了一個新方法(沒有黃色線),把原方法處理內容放在新寫的方法中,刪除原方法,並將新方法名改為原方法,發現還是沒有黃色線,再次運行,成功。

6、錯誤:java.lang.NoSuchMethodError: antlr.collections.AST

.getLine()I

解決:主要是Structs2 JAR包裏antlr(某個版本) 與 Hibernate中的antlr(某個版本)沖突,只要刪除Structs 2中的低版本的antlr(某個版本)就可以了。

7、錯誤; ognl.OgnlException: target is null for setProperty(null, "crcredit", [Ljava.lang.String;@3279afef)

解決:檢查實體類中所有set、get方法都正確,並且在action類中,get、set方法後面要大寫,比如變量為cs,se方法為setCs(),get方法為getCs()

使用SSH框架遇到的錯誤總結