`

attempt to create saveOrUpdate event with null entity

阅读更多
今天在进行Struts、Spring、Hibernate的整合配置时,碰到一系列的问题,其中有一个是:

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

    at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:40)

    at org.hibernate.event.SaveOrUpdateEvent.<init>(SaveOrUpdateEvent.java:23)

    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:518)

    at org.hibernate.impl.SessionImpl.save(SessionImpl.java:514)

刚开始忙活了半天,没能解决,后来在网上找到了一篇博文,地址如下:http://www.blogjava.net/sxyx2008/archive/2009/10/19/298821.html?opt=admin

以下部分内容转载上面:

从上面的异常信息可以看出是在Hibernate进行save的时候检测到bean为null

1)        大致从这几个方面来分析原因:

2)        Hibernate(*.hbm.xml)映射文件是否错误

3)        DAO层代码是否错误

4)        检查Action及视图层jsp页面等

从上面几个逐个检查后得出的结论为第四条

首先看Action中的代码


private Employee employee;

    public Employee getEmployee() {

        returnemployee;

    }

    publicvoid setEmployee(Employee employee) {

        this.employee = employee;

    }


这里employee是我们观察的重点

再看jsp中的代码

<s:form action="saveEmployee.action">

        <s:textfield name="empName" label="empName"></s:textfield>

        <s:textfield name="age" label="age"></s:textfield>

        <s:textfield name="sex" label="sex"></s:textfield>

        <s:textfield name="context" label="context"></s:textfield>

        <s:submit value="注册" theme="simple"></s:submit>

        <s:reset value="取消" theme="simple"></s:reset>

</s:form>


大家注意<s:textfield/>中name属性的值

很显然错误发生在此处修改如下即可:

<s:form action="saveEmployee.action">

        <s:textfield name="employee.empName" label="empName"></s:textfield>

        <s:textfield name="employee.age" label="age"></s:textfield>

        <s:textfield name="employee.sex" label="sex"></s:textfield>

        <s:textfield name="employee.context" label="context" value=""></s:textfield>

        <s:submit value="注册" theme="simple"></s:submit>

        <s:reset value="取消" theme="simple"></s:reset>

    </s:form>


由此我们得出的结论是:

在jsp页面中一定要保持页面中各个控件的name属性与Action中模型驱动对象的名字一致否则就会报错。

按照上述方法解决之后,发现还是不得行,出现下面的错误:

Cannot open connection; uncategorized SQLException for SQL [???]; SQL state [null]; error code [0]; Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES)); nested exception is org.apache.commons.dbcp.SQLNestedException: Cannot create PoolableConnectionFactory (Access denied for user 'root'@'localhost' (using password: YES))
后来仔细检查了applicationContext.xml文件后发现,原来是属性密码设置错了,本来应该为123,我居然设置成root了,改过之后,就能正常连接数据库了。
分享到:
评论

相关推荐

    Ionic日期选择插件

    Ionic框架是一款基于AngularJS和Apache Cordova的开源移动应用开发框架,它允许开发者使用Web技术(HTML、CSS、JavaScript)来构建跨平台的原生移动应用。在 Ionic 中,经常需要与用户交互处理日期和时间,这就需要...

    An attempt to read, understand, and implement the AUTOSAR SWS Po

    An attempt to read, understand, and implement the AUTOSAR SWS Port Driver according to the specification in a demo full-layered AUTOSAR a…

    A Practical Guide to Designing with Data.pdf

    Over the years, I have been digging through large data sets both for work and pleasure. I love numbers, charts, graphs, visualizations, ...and visualizations become easier to create.

    Easy Mobile

    Easy Mobile is our attempt to create a many-in-one Unity package that greatly simplifies the implementation of de facto standard features of mobile games including advertising, in-app purchasing, game...

    orcad15.7 破解方法

    orcad15.7 安装问题解决:An application has made an attempt to load the C runtime library incorrectly. Please ccontact the application"s support team for more information!

    AT89C2051 RS232

    AT89C2051是一款8位微控制器,由美国Atmel公司生产,属于8051系列的单片机。它具有低功耗、高性能的特点,适用于各种嵌入式应用,包括工业控制、消费电子和家用电器等。RS232,则是一种常见的串行通信接口标准,用于...

    VclZip pro v3.10.1

    Modified the SFX code (the code used to create the SFX stub distributed with VCLZip) so that it handles filenames that have been run through an OEM Conversion. The SFX was losing accented characters. ...

    mksysb报错解决方法[归纳].pdf

    《mksysb报错解决方法的详细指南》 在软件开发过程中,系统备份是确保数据安全和系统稳定性的重要步骤。然而,有时在执行mksysb命令进行系统备份时,可能会遇到各种报错,这可能对系统的正常运行造成影响。...

    Android代码-HeaderFooterGridView

    HeaderFooterGridView 头尾GridView 源码地址:ProjectX 介绍 支持AUTO_FIT模式,头尾模式有两种,无反射代码。 截图 先决条件 minSdkVersion 4 ...hfgContent.addHeaderItem(headerItem, null, true); hfgCont

    pb双击打开错误方式的修复

    PB,全称PowerBuilder,是一种流行的面向对象的编程环境,主要用于开发企业级应用程序,特别是数据库应用。当你在尝试双击打开PB项目时遇到错误,这可能是由于多种原因引起的,包括注册表问题、软件版本不兼容、环境...

    smoke dx10 Copyright 2007 NVIDIA Corporation

    IN NO EVENT SHALL NVIDIA扴 AGGREGATE LIABILITY TO DEVELOPER OR ANY OTHER PERSON OR ENTITY CLAIMING THROUGH OR UNDER DEVELOPER EXCEED THE AMOUNT OF MONEY ACTUALLY PAID BY DEVELOPER TO NVIDIA FOR THE ...

    Pro LINQ: Language Integrated Query in C# 2010 (含源码)

    How to query Databases with LINQ to SQL, write your own entity classes, and understand how to handle concurrency conflicts. Who this book is for This book is written for the proficient C# developer, ...

    DB2数据库跨平台备份与恢复

    SQL2570N 错误的全称是“An attempt to restore on target OS from a backup created on source OS failed due to the incompatibility of operating systems or an incorrect specification of the restore command...

    企业进销存管理系统 系统开发

    主要功能 进销存管理是企业日常经营管理中十分重要的一个组成部分,传统的手工管理方式呈现出越来越多的弊端。在手工管理模式下,统计、汇总处理时的工作量极其繁重,处理效率非常低,领导也无法及时了解企业资金...

    Test Driven Development with Python 2nd Edition.pdf

    This book is my attempt to share with the world the journey I’ve taken from “hack‐ ing” to “software engineering”. It’s mainly about testing, but there’s a lot more to it, as you’ll soon see....

    KafkaOffsetMonitor监控工具2017年1月发布的版本

    Created function tryParseOffsetMessage to attempt to parse a kafka offset message retrieved from the internal committed offset topic: Handles messages of other types and questionable correctness. ...

Global site tag (gtag.js) - Google Analytics