ssh学习中遇到的异常!

来源:互联网 发布:php编程 第3版 pdf 编辑:程序博客网 时间:2024/06/01 01:33

    

Bean property 'AuthorDao' is not writable or has an invalid setter method.

其中的配置文件中 类名不符合其规范

如: Author Author=null; (最好不要这样 容易出错!)

*******************************************************************************

java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity

一般是因为jsp页面传的对象属性不对 如:

<s:textfield name="author.username" label="name"></s:textfield>

但action中是 Author a; 故应修改为:

<s:textfield name="a.username" label="name"></s:textfield>

*******************************************************************************

Write operations are not allowed in read-only mode

此原因是因为事务的配置为题:

<!-- 配置事务管理器 -->

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">

   <property name="sessionFactory">

    <ref bean="sessionFactory"/>

   </property>

</bean>

<!-- 配置事务的传播特性 -->

<tx:advice id="txAdvice" transaction-manager="transactionManager">

   <tx:attributes>

    <tx:method name="add*" propagation="REQUIRED"/>

    <tx:method name="del*" propagation="REQUIRED"/>

    <tx:method name="modify*" propagation="REQUIRED"/>

    <tx:method name="*" read-only="true"/>

   </tx:attributes>

</tx:advice>

<!-- 那些类的哪些方法参与事务 -->

<aop:config>

   <aop:pointcut id="allManagerMethod" expression="execution(* com.bjm.service.impl.*.*(..))"/>

   <aop:advisor pointcut-ref="allManagerMethod" advice-ref="txAdvice"/>

</aop:config>

注意红色部分,一般出现这种错误 常见的是 execution(* com.bjm.service.impl.*.*(..))" 包路径不对 修改正确即可。

******************************************************

Cannot refer to a non-final variable conn inside an inner class defined in a different method

内部类引用了一个非final的变量,

内部类如果要引用外部类的变量,则该变量必须为final,这是规定

如:

public List getByArticleTypeID(final int articletype) {

   List list=(List)this.getHibernateTemplate().execute(

     new HibernateCallback()

     {

      public Object doInHibernate(org.hibernate.Session session) //throws HibernateException

      {

       List result = session.createCriteria(Article.class)

                           .add(Restrictions.eq("articletype.id", articletype))

                           .list();

       return result;

      }                            

     }

  

   );

注意:时刻记得Hibernate操作的是对象,而不是数据库。所以articletype是对象,通过articletype.id去查询articletype对象中的id属性

  

   return list;

}

*********************************************************************

Incorrect string value: '/xC4/xE3' for column 'title' at row 1

插入中文数据时就会有上面的报错。输入数字和英文就没有问题。。。此原因是编码问题。一般项目编码一致了,还要注意数据库编码。特别是mysql

********************************************************************

Illegal mix of collations (gbk_chinese_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'

我在中文查询的时候出现此问题,查询时候没问题 但分页的时候将KEY值作为SESSION传到后台的时候,如果KEY有中文则出错。分析一下是编码问题 修改HIBERNATE的

<property name="hibernate.connection.url">jdbc:mysql://localhost/myhot?characterEncoding=gbk</property>(与数据库编码相一致)问题解决!

***********************************************************************************

Cannot delete or update a parent row: a foreign key constraint fails (`myhot/articleop`, CONSTRAINT `FK21597557252B1253` FOREIGN KEY (`articleid`) REFERENCES `article` (`id`))

在hibernate多对一关系表的 一方的删除时候 出现此异常,

配置文件如下:<many-to-one name="article" column="articleid" lazy="false"/> (cascade="all" 也没解决问题)

目前修改的方法为:修改数据库中的外键关联删除的时候为 cascade

另:在一的一端增加一个一对多,问题解决。

<set name="articleOp" cascade="all" inverse="true" >

          <key column="articleid"/><!-- 此处必须跟 manay to one的外键相同 -->

          <one-to-many class="com.bcm.model.ArticleOp" />

        </set>

******************************************************************************************************

Unable to load bean org.apache.struts2.dispatcher.multipart.MultiPartRequest (jakarta) - [unknown location]

出现此原因一般为STRUTS2的包问题 要么是缺少包,要么是S2SH包相冲突。STRUTS2的包不用太新的

如:

 

*********************************************************************************

严重: Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ArticleDao' defined in file [E:/lw/apache-tomcat-6.0.14/apache-tomcat-6.0.14/webapps/bcm/WEB-INF/classes/applicationContext-bean.xml]: Cannot resolve reference to bean 'sessionFactory' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:/lw/apache-tomcat-6.0.14/apache-tomcat-6.0.14/webapps/bcm/WEB-INF/classes/applicationContext-common.xml]: Invocation of init method failed; nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for article in class com.bcm.model.ArticleType

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in file [E:/lw/apache-tomcat-6.0.14/apache-tomcat-6.0.14/webapps/bcm/WEB-INF/classes/applicationContext-common.xml]: Invocation of init method failed; nested exception is org.hibernate.PropertyNotFoundException: Could not find a getter for article in class com.bcm.model.ArticleType

Caused by: org.hibernate.PropertyNotFoundException: Could not find a getter for article in class com.bcm.model.ArticleType

出现此原因一般是Hibernate的配置文件与类文件中的属性名存在不一致造成的。应该注意配置的时候要特别注意。

原创粉丝点击