hibernate3学习笔记(五) saveOrUpdate方法 - 编程入门网
:
13:45:00,140 WARN ConfigurationFactory:127 - No configuration found. Configuring ehcache from ehcache-failsafe.xml found in the classpath: jar:file:/D:/Java/MyEclipse%206.0/workspace/hb3demo/ehcache-1.2.3.jar!/ehcache-failsafe.xml 13:45:00,703 WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.UpdateTimestampsCache]; using defaults. 13:45:00,734 WARN EhCacheProvider:93 - Could not find configuration [org.hibernate.cache.StandardQueryCache]; using defaults. Hibernate: select this_.id as id0_0_, this_.name as name0_0_, this_.age as age0_0_ from user this_ id name/age 1 shenbin/28 2 chenyan/25 ======================================== Hibernate: update user set name=?, age=? where id=? ======================================== Hibernate: insert into user (name, age) values (?, ?) ======================================== Hibernate: select user0_.id as id0_, user0_.name as name0_, user0_.age as age0_ from user user0_ id name/age 1 shenbin/28 2 chenyan/24 3 yangye/23 提示: unsaved-value可以设定的值包括: any:总是存储 none:总是更新 null:id为null时存储(默认) valid:id为null或是指定值时存储 值得一提的是: 正如上面的代码所示,使用查询语句查出对象后,不能使用同一个session直接对对象进行修改操作。否则会抛出异常: Exception in thread "main" org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [com.hb3.pack_01.model.User#2] ...... 当然这并不是saveOrUpdate方法独有的。save和update等方法使用不当也会出现如上异常。 解决方法可新建session, 或参阅: http://www.blogjava.net/Unmi/archive/2007/08/10/135771.html http://blog.csdn.net/tmpfree/archive/2006/03/13/623516.aspx http://www.javaeye.com/topic/11581 |
凌众科技专业提供服务器租用、服务器托管、企业邮局、虚拟主机等服务,公司网站:http://www.lingzhong.cn 为了给广大客户了解更多的技术信息,本技术文章收集来源于网络,凌众科技尊重文章作者的版权,如果有涉及你的版权有必要删除你的文章,请和我们联系。以上信息与文章正文是不可分割的一部分,如果您要转载本文章,请保留以上信息,谢谢! |