attempt to create saveOrUpdate event with null entity(s2sh整合出现的问题)
来源:互联网 发布:macbook 上必备软件 编辑:程序博客网 时间:2024/06/05 23:54
今天在进行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: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了,改过之后,就能正常连接数据库了。
- attempt to create saveOrUpdate event with null entity(s2sh整合出现的问题)
- # s: attempt to create saveOrUpdate event with null entity
- attempt to create saveOrUpdate event with null entity
- attempt to create saveOrUpdate event with null entity
- attempt to create saveOrUpdate event with null entity 问题解决
- 【Bug解决】attempt to create saveOrUpdate event with null entity
- SSH开发问题——attempt to create saveOrUpdate event with null entity
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- SSH 500错误 java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity
- java.lang.IllegalArgumentException: attempt to create saveOrUpdate event with null entity异常的易被忽略的原因
- attempt to create delete event with null entity解决办法
- attempt to create merge event with null entity;
- attempt to create delete event with null entity
- attempt to create delete event with null entity解决办法
- Eclipse快捷键大全(转载)
- 屏蔽Home键
- Android 程式开发:(五)发送通知 —— 5.1“状态栏”Notification通知
- [转]Sharding with Hibernate Shards
- JDBC
- attempt to create saveOrUpdate event with null entity(s2sh整合出现的问题)
- 分享42个超棒的智能手机摄影画廊
- Android网络多线程断点续传下载(转)
- linux INIT_WORK 创建工作队列
- dxf素材和dxf、plt、dst看图软件
- Wijmo 更优美的jQuery UI部件集:运行时处理Wijmo GridView数据操作
- 网页中显示当前时间日期
- Linux查看系统信息的一些命令及查看已安装软件包的命令
- 分享一个超棒的jQuery的单页面滚动导航设计插件 - jQuery one page nav