`

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日期选择插件

    感谢gocaizi贡献出来的代码,我在此基础上进行了一些修改 http://blog.csdn.net/u013276665/article/details/50001083

    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...

    AT89C2051 RS232

    AT89C2051与上位机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. ...

    Business Intelligence and the Cloud(Wiley,2014)

    It starts with a discussion of the media hype around cloud computing and attempt to pull together what industry experts are saying in order to create a unified definition. Once this foundation is ...

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

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

    Android代码-HeaderFooterGridView

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

    Economics_10E

    more money in an attempt to stimulate a flagging economy. And there is uncertainty about fiscal policy as a trillion dollar deficit interacts with an aging population to create a national debt time ...

    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, ...

    Programming with GNU software 2

    This book is neither a...attempt to guide you through the process of choosing, configuring and using GNU tools. We will do this by developing an example project demonstrating the actual use of each tool.

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

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

    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. ...

    GISandCAMapplications.rar_CSharp Canvas_cad_cad cam_tools drawin

    CanvasGIS is an object oriented 2D ... Canvas is an attempt to create a component that will serve them all. CanvasGIS是一个面向对象的2D图形绘制组件。它是MVisionTech开源GIS和数据可视化框架的一部分。

Global site tag (gtag.js) - Google Analytics