索引

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: 当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'COMPONENT' 中的标识列插入显式值。

4. 如何让struts配置文件ApplicationResources.properties生效

5. eclipse java.lang.OutOfMemoryError: Java heap space 解决方案

6. Spring2 struts2 hibernate3 后台测试时报的错 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>元素映射了相应数据库表的主键字段,对其子元素<generator class="">,其中class的取值可以为increment、identity、sequence、hilo、native……等,更多的可参考hibernate参考文档,一般取其值为native 功能是适应本地数据库。

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>

看看数据库表中的 id 是不是自增长类型,如果是自增长类型,把<generator class="assigned" />中assigned改为identity

(vipId的类型为自增长)

2. org.hibernate.exception.SQLGrammarException: could not update

错误原因:

  xxx.hbm.xml与数据库表字段类型不匹配。

解决方法:

  重新反转生成hbm文件。或者手动修改相应字段为匹配类型。

3. com.microsoft.sqlserver.jdbc.SQLServerException:

4. 如何让struts配置文件ApplicationResources.properties生效

在src目录下添加文件struts.properties文件,并在其中书写一行

struts.custom.i18n.resources=com.comp.struts.resources.ApplicationResources

重启tomcat,即可生效

国际化将文件转换为二进制方法:

native2ascii -encoding UTF-8 ApplicationResources.properties ApplicationResources_zh_CN.properties

参考文献:

ssh之struts第一篇:struts国际化: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 有启动参数里设置jvm大小,因为eclipse运行时自己也需要jvm,所以eclipse.ini里设置的jvm大小不是具体某个程序运行时所用jvm的大小,这和具体程序运行的jvm大小无关。

那么怎么才能设置某个程序的jvm大小呢(当然控制台运行的话不会存在这个问题,如:java -Xms256m -Xmx1024m classname,这样就可以把当前程序的jvm大小给设定)?

因为eclipse里默认的一个程序的jvm配置为:-Xms8m -Xmx128m,所以我们的处理耗内存比较大时需要手动调整一下,以便不会内存溢出。具体的设置方法为:

选中被运行的类,点击菜单‘run->run...’,选择(x)=Argument标签页下的vm arguments框里输入 -Xmx512m, 保存运行就ok了

因为我使用的是tomcat服务器,可以在tomcat configure 的java标签下面直接进行修改。修改方式如下:

打开 configure tomcat,在 Java 选项卡中,下方,会有
Inital memory Pool:  
Maximum memory Pool:
Thread stack size:
三个输入框,在这里即可不用做上面的操作,直接配置内存大小,只需要设置
Inital memory Pool 为 256
Maximum memory Pool 为 512

点击确定后,重启tomcat 生效。

但这种方法只能作用于手动启动tomcat,使用eclipse启动时还是会报错。

在eclipse中配置java内存的启动参数,要采用下面的方法:
A.windows->preference->java->instal jres->edit,增加参数:-Xms256m -Xmx512m
或者
B.windows->preferences..->tomcat->jvm..->jvm文本框里,添加-Xms256m -Xmx512m

如果使用myeclipse,
窗口->首选项->MyEcliipse->Application Servers->Tomcat->Tomcat5.x->JDK->Optional Java VM arguments中填写一下内容。
-Xms128m -Xmx256m
-Dcom.sun.management.jmxremote=true

 参考文献:

如何修改tomcat内存大小:http://edu.codepub.com/2010/0327/21418.php

增加eclipse启动的Tomcat内存的方法: http://wallimn.javaeye.com/blog/693158

  

6. Spring2 struts2  hibernate3 后台测试时报的错 Exception in thread "main" java.lang.NoSuchMethodError: org.objectweb.asm.ClassWriter. <init> 解决方案

因为cglib 包和asm包冲突

开始用的cglib包是cglib-2.1.3.jar  ,后来换了一个cglib-nodep-2.2.jar才测试通过.

7. Oracle Database Error ORA-02289  ORA-02289 sequence does not exist

表示系统未找到相应的sequence,有以下两种可能:

(1)数据库访问用户的权限不够,应该更换用户或增加权限以访问用户。

(2)hibernate 映射文件配置不正确,映射文件中的id采用oracle自动生成时需要采用native方式,若使用hibernate时采用sequence方式。hibernate会默认查找"hibernate_sequence"这一序列。xml映射文件中的子元素generator来说明主键的产生方式,此处指定的是“native”,表示根据数据库来选择,比如,对于Oracle数据库,它会去寻找一个sequence(默认情况下,它会去寻找一个名为“hibernate_sequence”的sequence),我们可以用参数param来指定一个sequence。而property用来指定Student.java类中的属性和Student数据库表之间的对应关系,以及各个字段的数据类型。在这个例子中,我们指定的数据类型是Java语言中的数据类型(此时需要指定引用类型数据),我们也可以使用Hibernate中自定义的数据类型,限于篇幅,在本文中不一一讲解。

 

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请检查Role类的主键属性是否是封装类型。例如:Integer,Long ……。不能是int,long等数据类型。

当 IDENTITY_INSERT 设置为 OFF 时,不能为表 'COMPONENT' 中的标识列插入显式值
分析:也许你的id是这样配置的:
<id name="id" type="integer">
            <column name="id" />
            <generator class="increment" />
</id>

increment是由Hibernate自动以自增的方式生成主键
identity是由底层数据库生成的标识符
当数据库中的ID为自动增长的时候采用increment当然会报“无法显示为主键插入值”

把主键生成方式改为identity或者你的操作表的主键没有被设置为自动增长。
 posted on 2010-06-23 20:08  TechNick  阅读(1404)  评论(0编辑  收藏  举报