DANCE WITH JAVA

开发出高质量的系统

常用链接

统计

积分与排名

好友之家

最新评论

hibernate 3.2新的Session接口与之前接口的不同

hibernate 3中的session接口的不同
hibernate3.2版本中session出现了2个
新session接口:org.hibernate.Session
老session接口:org.hibernate.classic.Session
顾名思义,classic包下的session就是以前常用的session,新的这个相比老的有很大变化。下边详细列出
1,去掉了所有的find方法
在新的session接口中没有find方法,而在老的session接口中把find全部注释成deprecated了。
2,去掉所有的saveOrUpdateCopy,使用merge代替,这是classic.Session注释中的一段原话.
/**
  * Copy the state of the given object onto the persistent object with the same
  * identifier. If there is no persistent instance currently associated with
  * the session, it will be loaded. Return the persistent instance. If the
  * given instance is unsaved or does not exist in the database, save it and
  * return it as a newly persistent instance. Otherwise, the given instance
  * does not become associated with the session.
  *
  * @deprecated use {@link org.hibernate.Session#merge(String, Object)}
  *
  * @param object a transient instance with state to be copied
  * @return an updated persistent instance
  */
注意这句:@deprecated use {@link org.hibernate.Session#merge(String, Object)}
3,去掉了iterate方法
给出的注释是使用createQuery,自己获得iterate
4,去掉了filter方法
@deprecated use {@link #createFilter(Object, String)}.{@link Query#list}
给出的注释说用createFilter代替,实际就是自己从createFilter获得query然后自己查询
5,增加了一些方法
具体自己看api吧,主要是提供了一些新的功能。
总结:
从上边的改变不难看出hibernate对于接口的设定观念改变了。

以前的策略是:
尽量给出全的接口,这样减少用户的代码量,所以filter直接返回collection,iterate直接返回
iterate。但这样的结果是过度的提供接口,造成了学习上的负担和选择上的负担。如何记住这些函数,如何在众多函数
中选择是个麻烦事情。
凡是做java的都知道,用一个java的东西最辛苦的是选择,在开源的世界里边选择一个适合自己的工程,再在这个选择的工程里边选择实现方法
因为可能提供很多种实现方法,而且有些还是deprecated的。

现在的策略:
尽量简化接口,或减少函数,或者简化函数名,例如把saveOrUpdateCopy变成merge。
这样的好处是记忆学习负担少。多写几句代码不是特别麻烦。其实我个人来讲更喜欢现在的感觉。
以前的策略其实很大程度上是满足程序员的个人需求,更有成就感。但确不适合使用者的需求。

ok,无论如何现在的情况是更好了。

 

posted on 2007-07-28 22:37 dreamstone 阅读(8523) 评论(3)  编辑  收藏 所属分类: dao层框架

评论

# re: hibernate 3.2新的Session接口与之前接口的不同 2010-07-07 16:38 淘宝网

hibernate3.2版本中session出现了2个
新session接口:org.hibernate.Session  回复  更多评论   

# re: hibernate 3.2新的Session接口与之前接口的不同 2012-03-07 16:18 胡强

学习了  回复  更多评论   

# re: hibernate 3.2新的Session接口与之前接口的不同 2013-01-07 16:18 刘3

刚知道,学习了  回复  更多评论   


只有注册用户登录后才能发表评论。


网站导航: