开发者社区> 问答> 正文

整合ssh时报错:Messages: attempt to create saveOrUpdate event with null entity

jsp数据提交页面:
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
<s:form action="userAction" namespace="/user" method="post">
    <table width="200" border="1">
        <tr>
            <td>name</td>
            <td><s:textfield name="user.name"/></td>
        </tr>
        <tr>
            <td>password</td>
            <td><s:textfield name="user.pwd"/></td>
        </tr>
        <tr>
            <td colspan="2"><s:submit value="submit"/></td>
        </tr>
    </table>
</s:form>
</body>
</html>
控制台报错:

17:41:16,129 ERROR ParametersInterceptor:34 - Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'user.name' on 'class $Proxy10: Error setting expression 'user.name' with value '[Ljava.lang.String;@12dcbd'
17:41:16,180 ERROR ParametersInterceptor:34 - Developer Notification (set struts.devMode to false to disable this message):
Unexpected Exception caught setting 'user.pwd' on 'class $Proxy10: Error setting expression 'user.pwd' with value '[Ljava.lang.String;@1cbcf19'
um----------------------:null
 dao的实现类:

public class S3Impl implements UserDao{

    private SessionFactory sessionFactory = null;
    
    public void setSessionFactory(SessionFactory sessionFactory) {
        this.sessionFactory = sessionFactory;
    }

    @Override
    public boolean create(UserModel um) {
        
        Session session = sessionFactory.getCurrentSession();
        session.save(um);

        return true;
    }

}
 页面报错:

Struts Problem Report
Struts has detected an unhandled exception: 

Messages: attempt to create saveOrUpdate event with null entity 
 
File: org/hibernate/event/spi/SaveOrUpdateEvent.java 
Line number: 62

展开
收起
a123456678 2016-03-16 11:38:25 2972 0
1 条回答
写回答
取消 提交回答
  • <struts>
     
        <constant name="struts.devMode" value="true" />
        <constant name="struts.i18n.encoding" value="UTF-8"/>
        <constant name="struts.ui.theme" value="simple"></constant>
         
        <constant name="struts.objectFactory" value="spring"/>
     
        <package name="user" namespace="/user" extends="struts-default">
            <action name="userAction" class="userAction">
                <result name="SUCCESS">/list.jsp</result>
                <result name="ERROR">/error.jsp</result>
            </action>
        </package>
     
    </struts>
    
    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
        xsi:schemaLocation="
    http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://www.springframework.org/schema/tx
    http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    ">
        <bean name="userAction" class="cn.xiaoxing.s3.action.UserAction" scope="prototype">
            <property name="userEbi" ref="userEbi"></property>
        </bean>
        <bean name="userEbi" class="cn.xiaoxing.s3.business.ebo.UserEbo">
            <property name="userDao" ref="S3Impl"></property>
        </bean>
         
        <bean name="S3Impl" class="cn.xiaoxing.s3.dao.impl.S3Impl">
            <!-- ref="dbConfig":表示要注意哪个对象 -->
            <property name="sessionFactory" ref="hbConfig"></property>
        </bean>
         
        <!-- 在Spring的application context中创建 SessionFactory -->
        <bean id="hbConfig" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
            <!-- 把连接数据信息注入到dbConfig -->
            <property name="dataSource" ref="dataSource"></property>
             
            <!-- 资源注册 -->
            <property name="mappingResources">
                <list>
                    <value>cn/xiaoxing/s3/vo/UserModel.hbm.xml</value>
                </list>
            </property>
             
            <!-- 可选配置 -->
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
                    <prop key="hibernate.show_sql">true</prop>
                    <prop key="hibernate.format_sql">true</prop>
                    <prop key="hibernate.current_session_context_class">org.springframework.orm.hibernate4.SpringSessionContext</prop>
                </props>
            </property>
        </bean>
     
        <!-- 配置数据源 -->
        <bean name="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
            <property name="driverClassName">
                <value>com.mysql.jdbc.Driver</value>
            </property>
            <property name="url">
                <value>jdbc:mysql://localhost:3306/test?useUnicode=true&amp;characterEncoding=UTF-8</value>
            </property>
            <property name="username" value="root"></property>
            <property name="password" value="123456"></property>
        </bean>
         
        <!-- 第二种方法:spring事务配置,拟管理类上需要加上@transactional支持 
        <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
            <property name="dataSource" ref="dataSource"/>
        </bean>
        <tx:annotation-driven transaction-manager="txManager"/>
        -->
         
        <!-- 第一种方法:spring事务配置    -->
        <bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"> 
            <property name="sessionFactory" ref="hbConfig"></property>
        </bean> 
        <!--事务切入点配置-->
        <tx:advice id="txAdvice" transaction-manager="txManager">
            <tx:attributes>
                <tx:method name="get*" read-only="true" />
                <tx:method name="*" />
            </tx:attributes>
        </tx:advice>
        <!--配置切入点与被应用类关联-->
        <aop:config>
            <aop:pointcut id="myPointCut" expression="execution(* cn.xiaoxing.s3..*.*(..))"/>
            <aop:advisor advice-ref="txAdvice" pointcut-ref="myPointCut"/>
        </aop:config>
         
         
    </beans>
    2019-07-17 19:03:45
    赞同 展开评论 打赏
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Borgaonkar-New-Adventures-In-Spying-3G-And-4G-Users-Locate-Track-And-Monitor 立即下载
Customer Success Dashboard GoD 立即下载
Dynamic DDL Adding Structure to Streaming Data on the Fly 立即下载