eclipse 环境下整合 struts2+spring+hibernate 开发web应用常见问题及解答
1. org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save():
2. org.hibernate.exception.SQLGrammarException: could not update
3. com.microsoft.sqlserver.jdbc.SQLServerException: 當(dāng) IDENTITY_INSERT 設(shè)置為 OFF 時(shí),不能為表 'COMPONENT' 中的標(biāo)識(shí)列插入顯式值。
4. 如何讓struts配置文件ApplicationResources.properties生效
5. eclipse java.lang.OutOfMemoryError: Java heap space 解決方案
6. Spring2 struts2 hibernate3 后臺(tái)測(cè)試時(shí)報(bào)的錯(cuò) Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter.解決方案
7. Oracle Database Error ORA-02289 ORA-02289 sequence does not exist
8. org.hibernate.PropertyValueException: not-null property references a null or transient value.?
9. EJB異常:identifier of an instance of xx was altered from x to x
1. org.hibernate.id.IdentifierGenerationException: ids for this class must be manually assigned before calling save()
異常原因:
<id>元素配置不正確,<id>元素缺少其子元素<generator></generator>的配置。
解決方法:
<id>元素映射了相應(yīng)數(shù)據(jù)庫(kù)表的主鍵字段,對(duì)其子元素<generator class="">,其中class的取值可以為increment、identity、sequence、hilo、native……等,更多的可參考hibernate參考文檔,一般取其值為native 功能是適應(yīng)本地?cái)?shù)據(jù)庫(kù)。
exp:
<hibernate-mapping>
??? <class name="com.fqf.Vipdata" table="vipdata" catalog="test">
??????? <id name="vipId" type="java.lang.Integer">
??????????? <column name="vipId" />
??????????? <generator class="assigned" />
??????? </id>
??????? <property name="vipName" type="java.lang.String">
??????????? <column name="vipName" length="20" not-null="true" />
??????? </property>
??????? <property name="vipTitle" type="java.lang.String">
??????????? <column name="vipTitle" length="20" not-null="true" />
??????? </property>
??? </class>
</hibernate-mapping>
看看數(shù)據(jù)庫(kù)表中的 id 是不是自增長(zhǎng)類型,如果是自增長(zhǎng)類型,把<generator class="assigned" />中assigned改為identity
(vipId的類型為自增長(zhǎng))
2. org.hibernate.exception.SQLGrammarException: could not update
錯(cuò)誤原因:
xxx.hbm.xml與數(shù)據(jù)庫(kù)表字段類型不匹配。
解決方法:
重新反轉(zhuǎn)生成hbm文件。或者手動(dòng)修改相應(yīng)字段為匹配類型。
3. com.microsoft.sqlserver.jdbc.SQLServerException:
4. 如何讓struts配置文件ApplicationResources.properties生效
在src目錄下添加文件struts.properties文件,并在其中書寫一行
struts.custom.i18n.resources=com.comp.struts.resources.ApplicationResources
重啟tomcat,即可生效
國(guó)際化將文件轉(zhuǎn)換為二進(jìn)制方法:
native2ascii -encoding UTF-8 ApplicationResources.properties ApplicationResources_zh_CN.properties
參考文獻(xiàn):
ssh之struts第一篇:struts國(guó)際化:http://blog.csdn.net/rookieStudent/archive/2010/03/21/5401516.aspx
?
5. eclipse java.lang.OutOfMemoryError: Java heap space 解決方案
?eclipse java.lang.OutOfMemoryError: Java heap space 解決方案2008年11月24日 星期一 下午 01:57eclipse 有啟動(dòng)參數(shù)里設(shè)置jvm大小,因?yàn)閑clipse運(yùn)行時(shí)自己也需要jvm,所以eclipse.ini里設(shè)置的jvm大小不是具體某個(gè)程序運(yùn)行時(shí)所用jvm的大小,這和具體程序運(yùn)行的jvm大小無(wú)關(guān)。
那么怎么才能設(shè)置某個(gè)程序的jvm大小呢(當(dāng)然控制臺(tái)運(yùn)行的話不會(huì)存在這個(gè)問(wèn)題,如:java -Xms256m -Xmx1024m classname,這樣就可以把當(dāng)前程序的jvm大小給設(shè)定)?
因?yàn)閑clipse里默認(rèn)的一個(gè)程序的jvm配置為:-Xms8m -Xmx128m,所以我們的處理耗內(nèi)存比較大時(shí)需要手動(dòng)調(diào)整一下,以便不會(huì)內(nèi)存溢出。具體的設(shè)置方法為:
選中被運(yùn)行的類,點(diǎn)擊菜單‘run->run...’,選擇(x)=Argument標(biāo)簽頁(yè)下的vm arguments框里輸入 -Xmx512m, 保存運(yùn)行就ok了
因?yàn)槲沂褂玫氖莟omcat服務(wù)器,可以在tomcat configure 的java標(biāo)簽下面直接進(jìn)行修改。修改方式如下:
打開 configure tomcat,在 Java 選項(xiàng)卡中,下方,會(huì)有
Inital memory Pool:??
Maximum memory Pool:
Thread stack size:
三個(gè)輸入框,在這里即可不用做上面的操作,直接配置內(nèi)存大小,只需要設(shè)置
Inital memory Pool 為 256
Maximum memory Pool 為 512
點(diǎn)擊確定后,重啟tomcat 生效。
但這種方法只能作用于手動(dòng)啟動(dòng)tomcat,使用eclipse啟動(dòng)時(shí)還是會(huì)報(bào)錯(cuò)。
在eclipse中配置java內(nèi)存的啟動(dòng)參數(shù),要采用下面的方法:
A.windows->preference->java->instal jres->edit,增加參數(shù):-Xms256m -Xmx512m
或者
B.windows->preferences..->tomcat->jvm..->jvm文本框里,添加-Xms256m -Xmx512m
如果使用myeclipse,
窗口->首選項(xiàng)->MyEcliipse->Application Servers->Tomcat->Tomcat5.x->JDK->Optional Java VM arguments中填寫一下內(nèi)容。
-Xms128m -Xmx256m
-Dcom.sun.management.jmxremote=true
?參考文獻(xiàn):
如何修改tomcat內(nèi)存大小:http://edu.codepub.com/2010/0327/21418.php
增加eclipse啟動(dòng)的Tomcat內(nèi)存的方法: http://wallimn.javaeye.com/blog/693158
??
6. Spring2 struts2? hibernate3 后臺(tái)測(cè)試時(shí)報(bào)的錯(cuò) Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. <init> 解決方案
因?yàn)閏glib 包和asm包沖突
開始用的cglib包是cglib-2.1.3.jar? ,后來(lái)?yè)Q了一個(gè)cglib-nodep-2.2.jar才測(cè)試通過(guò).
7. Oracle Database Error ORA-02289 ORA-02289 sequence does not exist
表示系統(tǒng)未找到相應(yīng)的sequence,有以下兩種可能:
(1)數(shù)據(jù)庫(kù)訪問(wèn)用戶的權(quán)限不夠,應(yīng)該更換用戶或增加權(quán)限以訪問(wèn)用戶。
(2)hibernate 映射文件配置不正確,映射文件中的id采用oracle自動(dòng)生成時(shí)需要采用native方式,若使用hibernate時(shí)采用sequence方式。hibernate會(huì)默認(rèn)查找"hibernate_sequence"這一序列。xml映射文件中的子元素generator來(lái)說(shuō)明主鍵的產(chǎn)生方式,此處指定的是“native”,表示根據(jù)數(shù)據(jù)庫(kù)來(lái)選擇,比如,對(duì)于Oracle數(shù)據(jù)庫(kù),它會(huì)去尋找一個(gè)sequence(默認(rèn)情況下,它會(huì)去尋找一個(gè)名為“hibernate_sequence”的sequence),我們可以用參數(shù)param來(lái)指定一個(gè)sequence。而property用來(lái)指定Student.java類中的屬性和Student數(shù)據(jù)庫(kù)表之間的對(duì)應(yīng)關(guān)系,以及各個(gè)字段的數(shù)據(jù)類型。在這個(gè)例子中,我們指定的數(shù)據(jù)類型是Java語(yǔ)言中的數(shù)據(jù)類型(此時(shí)需要指定引用類型數(shù)據(jù)),我們也可以使用Hibernate中自定義的數(shù)據(jù)類型,限于篇幅,在本文中不一一講解。
?
8. ?org.hibernate.PropertyValueException: not-null property references a null or transient value.
表示數(shù)據(jù)庫(kù)的非空字段映射到本地的可為空的字段中。檢查是否沒(méi)有給非空字段賦值。
?
9. EJB異常:identifier of an instance of?xx was altered from?x to x請(qǐng)檢查Role類的主鍵屬性是否是封裝類型。例如:Integer,Long ……。不能是int,long等數(shù)據(jù)類型。
當(dāng) IDENTITY_INSERT 設(shè)置為 OFF 時(shí),不能為表 'COMPONENT' 中的標(biāo)識(shí)列插入顯式值分析:也許你的id是這樣配置的:
<id name="id" type="integer">
??????????? <column name="id" />
??????????? <generator class="increment" />
</id>
increment是由Hibernate自動(dòng)以自增的方式生成主鍵
identity是由底層數(shù)據(jù)庫(kù)生成的標(biāo)識(shí)符
當(dāng)數(shù)據(jù)庫(kù)中的ID為自動(dòng)增長(zhǎng)的時(shí)候采用increment當(dāng)然會(huì)報(bào)“無(wú)法顯示為主鍵插入值”
把主鍵生成方式改為identity或者你的操作表的主鍵沒(méi)有被設(shè)置為自動(dòng)增長(zhǎng)。
轉(zhuǎn)載于:https://www.cnblogs.com/destimarve/archive/2010/06/23/ssh2.html
總結(jié)
以上是生活随笔為你收集整理的eclipse 环境下整合 struts2+spring+hibernate 开发web应用常见问题及解答的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Android 笔记一
- 下一篇: 关于ibatis.net 和 Nhibe