1. 程式人生 > >SSH專案中遇到的問題

SSH專案中遇到的問題

1.

Struts has detected an unhandled exception:

Messages: antlr.collections.AST.getLine()I
File:	org/hibernate/hql/internal/ast/HqlSqlWalker.java
Line number:	929

  這個問題,每次都是重新編譯後還會出現這個異常,原因是Struts2框架自帶antlr2.7.2.jar和Hibernate框架自帶的ntlr2.7.7.jar衝突了故只要刪除低版本的antlr2.7.2.jar就行,但是antlr2.7.2.jar是Struts2框架自帶的,所以刪除後重新編譯還會再次出現,異常還是解決不了。

具體如下:
Window-->Preferences-->MyEclipse-->Project Libraries-->Struts 2.1 Libraries-->Core 你就會看到antlr2.7.2.jar,此時先勾選Enable advanced configuration,再去取消勾選antlr2.7.2.jar。

再去Workspace\.metadata\.me_tcat7\webapps\專案名\WEB-INF\lib下強制刪掉antlr2.7.2,重啟Tomcat,異常就不再出現。

兩者缺一不可。


 2.

hibernate 中 Provided id of the wrong type for class 異常

HTTP Status 500 - Provided id of the wrong type for class com.s_football.pojo.UserBean. Expected: class java.lang.Integer, got class java.lang.String; nested exception is org.hibernate.TypeMismatchException: Provided id of the wrong type for class com.s_football.pojo.UserBean. Expected: class java.lang.Integer, got class java.lang.String

  

收集資料後發現:在HibernateTemplate中的get方法僅僅可以查詢主鍵,不可以查詢其他欄位。其實是自己沒有考慮好,在開始的時候自己還有過這樣的疑問:get來查詢是怎麼對應欄位,而且查找出來只是單個的,並不是個List。但是沒有多想,現在用get來查詢其他欄位就丟擲了了這個異常。
其實看到這個異常就可以知道,肯定是型別錯誤,像我這個就是String型別轉int型別了(在使用get方法中)。
所以,檢查一下型別匹配就可以解決了,包括是不是也用get方法查詢其他欄位了(其實也是型別匹配的問題)