一開始用Struts+spring+hibernate 碰到了很多郁悶的問題,感覺特難。慢慢的遇到什么問題解決什么問題后感覺就沒那么痛苦了,一般的問題也就能搞定了!現(xiàn)在放到blog里.一來嘛:方便復(fù)習(xí),二嘛:為正在學(xué)習(xí)ssh框架的同行們提供點經(jīng)驗。
在使用junitStrutsTest時候,報錯:
java.lang.UnsupportedClassVersionError junitframeworkTestListener (Unsupported major.minor version 49.0)
原因是如果是jdk1.4的話,只能使用junit3.8以下版本,如果是使用jdk1.5的話,必須使用junit4.0以上版本。
javax.servlet.ServletException Cannot retrieve mapping for action companyNews :
struts-config.xml中沒有寫相關(guān)companyNews的action.
Cannot find ActionMappings or ActionformBeans collection
原因可能是:web.xml文件中沒有配置struts-config.xml的相關(guān)信息。
Failed to load or instantiate TagLibraryValidator class org.apache.taglibs.standard.tlv.JstlCoreTLV :
standard.jar沒有放在lib里面 或者是有其他版本沖突
hibernate3,對象中一對多的one方,必須寫private Set pays=new HashSet();,否則包錯java.lang.NullPointerException ,
而hibernate2中private Set pays;卻不報錯;
AbstractSaveEventListener - generated identifier 1, using strategy org.hibernate.id.IncrementGenerator
org.hibernate.PropertyValueException not-null property references a null or transient value com.xxx.yyy.company
at org.hibernate.engine.Nullability.checkNullability(Nullability.java72)
many to one 中的設(shè)置應(yīng)該設(shè)置為not-null=false ,設(shè)置為not-null=true則報以上錯誤
javax.naming.NameNotFoundException Name hibernate_connection_factory is not bound in this Context
原因:hibernate的數(shù)據(jù)庫映射.xml文件有配置錯誤,考試.大提示導(dǎo)致hibernate_connection_factory無法綁定數(shù)據(jù)庫。
例如many-to-one設(shè)置了以后,仍然在其中設(shè)置相沖突的property屬性。
java.lang.IllegalArgumentException id to load is required for loading
原因: session.load(Company.class,payForm.getCompanyId());
load()方法第二個參數(shù)必須是searlizable,并且必須是和數(shù)據(jù)庫映射類的屬性值類型一致,即使強制轉(zhuǎn)換都不行。
org.hibernate.LazyInitializationException could not initialize proxy - the owning Session was closed
解決辦法。
cmpy=(CompanyEdit)ss.load(CompanyEdit.class,companyId1);
Hibernate.initialize(cmpy);強制初始化cmpy,否則ss.close()后,cmpy將消失.
或者加入lazy=false 取消延遲加載也可以 但是影響性能
Deployment is out of date due to changes in the underlying project contents . You'll need to mannally 'Redeploy' the project to update the deployed archive.
原因
tomcat 中部署的某個文件的拒絕訪問影響了部署。
重啟后,去除tomcat中部署的文件。重新在eclipse中設(shè)置部署。
[WARN] JDBCExceptionReporter - SQL Error 904, SQLState 42000
[ERROR] JDBCExceptionReporter - ORA-00904 無效列名
[INFO] DefaultLoadEventListener - Error performing load command org.hibernate.exception.SQLGrammarException could ot load an entity [com.xxx.yyy.Sellinfo#1]
org.hibernate.exception.SQLGrammarException could not load an entity [com.xxx.yyy.Sellinfo#1]
.hbm.xml文件中的某個列名和數(shù)據(jù)庫中的不同。
ConnectionManager - unclosed connection, forgot to call close() on your session
原因:沒有關(guān)閉hibernate的session的transaction?;蛘邲]有關(guān)閉session
[WARN] SellCommentDAO - org.hibernate.ObjectDeletedException deleted object would be re-saved by cascade (remove
deleted object from associations) [com.xxx.yyy.SellComment#7]
原因:父親對象(one方)設(shè)置cascade=save-update 時,直接刪除子對象時,會報錯,
處理方法:save信息需要級聯(lián)操作,delete時候也要用相同的原理。
SellComment sellComment=new SellComment();
sellComment = (SellComment)session.load(SellComment.class,sellCommentId);獲取兒子對象
Long sellInfoId=sellComment.getSellInfo().getSellId();獲取父親id
SellInfo sellinfo=(SellInfo)session.load(SellInfo.class,sellInfoId);獲取父親對象
sellInfo.getSellComments().remove(sellComment);斷絕父子關(guān)系
sellComment.setSellInfo(null);斷絕子父關(guān)系
方法二:修改cascade=all 不是很好 可能其他地方不需要多余的級聯(lián)降低性能
前幾天發(fā)現(xiàn)原來很好用的系統(tǒng)總是報Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file 錯誤.
具體錯誤信息為:
HTTP Status 500 -type Exception report
Message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /index.jsp(1,1) Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file
"file:*****/WEB-INF/lib/struts.jar":
原因:測試發(fā)現(xiàn)更新了工程用的lib文件夾下的jar,發(fā)布時也發(fā)布了servlet.jar和jsp-api.jar。 它們有沖突
解決辦法:
方法一:把jsp-api.jar刪除就解決這個問題了。
方法二:將Tomcat換成6.0
我的解決辦法:刪除servlet.jar及與servlet相關(guān)的jar文件
在使用junitStrutsTest時候,報錯:
java.lang.UnsupportedClassVersionError junitframeworkTestListener (Unsupported major.minor version 49.0)
原因是如果是jdk1.4的話,只能使用junit3.8以下版本,如果是使用jdk1.5的話,必須使用junit4.0以上版本。
javax.servlet.ServletException Cannot retrieve mapping for action companyNews :
struts-config.xml中沒有寫相關(guān)companyNews的action.
Cannot find ActionMappings or ActionformBeans collection
原因可能是:web.xml文件中沒有配置struts-config.xml的相關(guān)信息。
Failed to load or instantiate TagLibraryValidator class org.apache.taglibs.standard.tlv.JstlCoreTLV :
standard.jar沒有放在lib里面 或者是有其他版本沖突
hibernate3,對象中一對多的one方,必須寫private Set pays=new HashSet();,否則包錯java.lang.NullPointerException ,
而hibernate2中private Set pays;卻不報錯;
AbstractSaveEventListener - generated identifier 1, using strategy org.hibernate.id.IncrementGenerator
org.hibernate.PropertyValueException not-null property references a null or transient value com.xxx.yyy.company
at org.hibernate.engine.Nullability.checkNullability(Nullability.java72)
many to one 中的設(shè)置應(yīng)該設(shè)置為not-null=false ,設(shè)置為not-null=true則報以上錯誤
javax.naming.NameNotFoundException Name hibernate_connection_factory is not bound in this Context
原因:hibernate的數(shù)據(jù)庫映射.xml文件有配置錯誤,考試.大提示導(dǎo)致hibernate_connection_factory無法綁定數(shù)據(jù)庫。
例如many-to-one設(shè)置了以后,仍然在其中設(shè)置相沖突的property屬性。
java.lang.IllegalArgumentException id to load is required for loading
原因: session.load(Company.class,payForm.getCompanyId());
load()方法第二個參數(shù)必須是searlizable,并且必須是和數(shù)據(jù)庫映射類的屬性值類型一致,即使強制轉(zhuǎn)換都不行。
org.hibernate.LazyInitializationException could not initialize proxy - the owning Session was closed
解決辦法。
cmpy=(CompanyEdit)ss.load(CompanyEdit.class,companyId1);
Hibernate.initialize(cmpy);強制初始化cmpy,否則ss.close()后,cmpy將消失.
或者加入lazy=false 取消延遲加載也可以 但是影響性能
Deployment is out of date due to changes in the underlying project contents . You'll need to mannally 'Redeploy' the project to update the deployed archive.
原因
tomcat 中部署的某個文件的拒絕訪問影響了部署。
重啟后,去除tomcat中部署的文件。重新在eclipse中設(shè)置部署。
[WARN] JDBCExceptionReporter - SQL Error 904, SQLState 42000
[ERROR] JDBCExceptionReporter - ORA-00904 無效列名
[INFO] DefaultLoadEventListener - Error performing load command org.hibernate.exception.SQLGrammarException could ot load an entity [com.xxx.yyy.Sellinfo#1]
org.hibernate.exception.SQLGrammarException could not load an entity [com.xxx.yyy.Sellinfo#1]
.hbm.xml文件中的某個列名和數(shù)據(jù)庫中的不同。
ConnectionManager - unclosed connection, forgot to call close() on your session
原因:沒有關(guān)閉hibernate的session的transaction?;蛘邲]有關(guān)閉session
[WARN] SellCommentDAO - org.hibernate.ObjectDeletedException deleted object would be re-saved by cascade (remove
deleted object from associations) [com.xxx.yyy.SellComment#7]
原因:父親對象(one方)設(shè)置cascade=save-update 時,直接刪除子對象時,會報錯,
處理方法:save信息需要級聯(lián)操作,delete時候也要用相同的原理。
SellComment sellComment=new SellComment();
sellComment = (SellComment)session.load(SellComment.class,sellCommentId);獲取兒子對象
Long sellInfoId=sellComment.getSellInfo().getSellId();獲取父親id
SellInfo sellinfo=(SellInfo)session.load(SellInfo.class,sellInfoId);獲取父親對象
sellInfo.getSellComments().remove(sellComment);斷絕父子關(guān)系
sellComment.setSellInfo(null);斷絕子父關(guān)系
方法二:修改cascade=all 不是很好 可能其他地方不需要多余的級聯(lián)降低性能
前幾天發(fā)現(xiàn)原來很好用的系統(tǒng)總是報Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file 錯誤.
具體錯誤信息為:
HTTP Status 500 -type Exception report
Message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: /index.jsp(1,1) Unable to read TLD "META-INF/tlds/struts-bean.tld" from JAR file
"file:*****/WEB-INF/lib/struts.jar":
原因:測試發(fā)現(xiàn)更新了工程用的lib文件夾下的jar,發(fā)布時也發(fā)布了servlet.jar和jsp-api.jar。 它們有沖突
解決辦法:
方法一:把jsp-api.jar刪除就解決這個問題了。
方法二:將Tomcat換成6.0
我的解決辦法:刪除servlet.jar及與servlet相關(guān)的jar文件