m​y​e​c​l​i​p​s​e​ ​环​境​下​整​合​开​发​ ​s​t​r​u​t​s​2​+​s​p​r​i​n​g​+​h​i​b​e​r​n​a​t​e​ ​常​见​问​题​及​解​答

myeclipse 

环境下整合开发

 

struts2+spring+hibernate 

常见问题及解答

 

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

改为

increment

 

 

 

(vipId

的类型为自增长

 

 

  

 

 

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

update

 

 

 

错误原因:

 

 

 

 

 

xxx.hbm.xml

与数据库表字段类型不匹配。

 

 

 

解决方法:

 

 

 

 

 

重新反转生成

hbm

文件。或者手动修改相应字段为匹配类型。

 

 

 

  

 

 

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

 

IDENTITY_INSERT 

设置为

 

OFF 

时,

不能为表

 

"COMPONENT" 

中的标识

列插入显式值。

 

分析:也许你的

id

是这样配置的:

  

<id name="id" type="integer">  

            

<column name="id" />  

            

<generator class="increment" />  

</id>

increment

是由

Hibernate

自动以自增的方式生成主键

  

identity

是由底层数据库生成的标识符

  

当数据库中的

ID

为自动增长的时候采用

increment

当然会报

无法显示为主键插

入值

  

 

把主键生成方式改为

identity

或者你的操作表的主键没有被设置为自动增长。

 

 

 

  

 

 

4. 

如何让

struts

配置文件

ApplicationResources.properties

生效

 

 

 

src

目录下添加文件

struts.properties

文件,并在其中书写一行

 

 

 

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

esources 

 

 

重启

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

posted @ 2014-06-10 09:15  ☆云☆  阅读(309)  评论(0编辑  收藏  举报