ssh整合过程中遇到的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ScongHW/article/details/82931842

1、异常: Line: 230 - com/opensymphony/xwork2/spring/SpringObjectFactory.java:230:-1

原因:出现该异常有两个原因,1.没有使用到spring的jar包  2.没有配置spring监听器

解决方法:

  1. 将spring的jar包移除
  2. 在web.xml 中配置监听器
  <!-- 配置spring配置文件的位置,classpath:在类目录下 -->
  <context-param>
  	<param-name>contextConfigLocation</param-name>
  	<param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!-- 配置spring上下文监听器,当web容器一启动就完成spring的初始化工作 -->
  <listener>
  	<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

2、异常:Write operations are not allowed in read-only mode (FlushMode.MANUAL): Turn your Session into FlushMode.COMMIT/AUTO or remove 'readOnly' marker from transaction definition.

原因:web.xml文件中配置了一个过滤器OpenSessionInViewFilter,该过滤器的作用是阻止hibernate延迟加载。

      但是,它会将所有未在spring事务详情中配置事务边界的事务的read-only值,设置为true。

	<filter>
		<filter-name>openSession</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
	</filter>
	<filter-mapping>
		<filter-name>openSession</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

解决方法1: 配置事务边界,将要执行的事务在spring配置文件中配置,例如:

	<tx:advice id="txAdvice" transaction-manager="txManager">
		<tx:attributes>
			<tx:method name="add*"/>
			<tx:method name="update*"/>
			<tx:method name="delete*"/>
			<tx:method name="save*"/>
			<tx:method name="find*" read-only="true"/>
		</tx:attributes>
	</tx:advice>

解决方法2:在配置的opensession过滤器中修改默认配置,例如:

(我在web.xml中这样配置之后,更新操作无法实现,建议两种方式都配置上)

	<filter>
		<filter-name>openSession</filter-name>
		<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
		<init-param>
			<param-name>flushMode</param-name>
			<param-value>AUTO</param-value>
		</init-param>
	</filter>
	<filter-mapping>
		<filter-name>openSession</filter-name>
		<url-pattern>/*</url-pattern>
	</filter-mapping>

3、 问题:在一对多关系中,更新一的一方的数据时,多的一方的外键会被清空。

Hibernate:
    update
        crm_department
    set
        depName=?
    where
        depId=?
Hibernate:
    update
        crm_post
    set
        depId=null
    where
        depId=?

解决方法:在一的一方放弃关系的维护,即:在映射文件的set属性上,设置inverse="true"。

猜你喜欢

转载自blog.csdn.net/ScongHW/article/details/82931842