关于merge与IdTransferringMergeEventListener的用法
2012-09-12 15:34
363 查看
newObj = getHibernateTemplate().merge(obj);
obj是一个游离对象,该方法将把obj中的属性更新到与obj主键一致的持久对象中,并返回该持久对象newObj。如果没有对应的持久对象,将会新建一个持久对象并将属性拷贝进去,并返回新对象。
参考:
Copy the state of the given object onto the persistent object with the same identifier. Follows JSR-220 semantics.
Similar to
Note that
如果上述方法新建了一个持久对象,持久对象的id并不会拷贝到obj中。如果想要拷贝到obj中,要注册IdTransferringMergeEventListener监听器。
例如:
参考
Extension of Hibernate's DefaultMergeEventListener, transferring the ids of newly saved objects to the corresponding original objects (that are part of the detached object graph passed into the
Transferring newly assigned ids to the original graph allows for continuing to use the original object graph, despite merged copies being registered with the current Hibernate Session. This is particularly useful for web applications
that might want to store an object graph and then render it in a web view, with links that include the id of certain (potentially newly saved) objects.
The merge behavior given by this MergeEventListener is nearly identical to TopLink's merge behavior. See PetClinic for an example, which relies on ids being available for newly saved objects: the
Typically specified as entry for LocalSessionFactoryBean's "eventListeners" map, with key "merge".
obj是一个游离对象,该方法将把obj中的属性更新到与obj主键一致的持久对象中,并返回该持久对象newObj。如果没有对应的持久对象,将会新建一个持久对象并将属性拷贝进去,并返回新对象。
参考:
Copy the state of the given object onto the persistent object with the same identifier. Follows JSR-220 semantics.
Similar to
saveOrUpdate, but never associates the given object with the current Hibernate Session. In case of a new entity, the state will be copied over as well.
Note that
mergewill not update the identifiers in the passed-in object graph (in contrast to TopLink)! Consider registering Spring's
IdTransferringMergeEventListenerif you would like to have newly assigned ids transferred to the original object graph too.
如果上述方法新建了一个持久对象,持久对象的id并不会拷贝到obj中。如果想要拷贝到obj中,要注册IdTransferringMergeEventListener监听器。
例如:
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="eventListeners"> <map> <entry key="merge"> <bean class="org.springframework.orm.hibernate3.support.IdTransferringMergeEventListener"/> </entry> </map> </property> </bean>
参考
Extension of Hibernate's DefaultMergeEventListener, transferring the ids of newly saved objects to the corresponding original objects (that are part of the detached object graph passed into the
mergemethod).
Transferring newly assigned ids to the original graph allows for continuing to use the original object graph, despite merged copies being registered with the current Hibernate Session. This is particularly useful for web applications
that might want to store an object graph and then render it in a web view, with links that include the id of certain (potentially newly saved) objects.
The merge behavior given by this MergeEventListener is nearly identical to TopLink's merge behavior. See PetClinic for an example, which relies on ids being available for newly saved objects: the
HibernateClinicand
TopLinkClinicDAO implementations both use straight merge calls, with the Hibernate SessionFactory configuration specifying an
IdTransferringMergeEventListener.
Typically specified as entry for LocalSessionFactoryBean's "eventListeners" map, with key "merge".
相关文章推荐
- 从源码说说dispatchTouchEvent与onTouchEvent的关系以及OnTouchListener的用法
- js函数中关于this与event的用法
- SQL中MERGE关于更新、插入的一种用法
- 关于 来源: volmgr Event ID: 46 故障转储初始化未成功 的问题
- 关于C# 委托(delegate)与事件(event)的用法及事例
- HTML、CSS里面关于 id、class、name 属性的区别和用法
- 关于ViewGroup中requestDisallowInterceptTouchEvent的用法
- 关于ViewGroup中requestDisallowInterceptTouchEvent的用法
- 关于TrackMouseEvent用法总结
- 关于 addEventListener, removeEventListener
- 关于C# 委托(delegate)与事件(event)的用法及事例
- 关于MERGE 的用法
- 关于在myeclipse中用jsp访问实体bean的一个问题的解决(Exception sending context initialized event to listener instance of class)
- 关于gevent的协程间通信及队列和事件event用法 推荐
- [转摘CSDN_cnkiminzhuhu(ID)]详尽解析window.event对象及用法实例
- 关于对“如何使用hibernate的event/eventlistener ”的补充
- Mysql 关于last_insert_id() 函数的用法
- addEventListener()与removeEventListener() 用法详解
- 有关于addEventListener以及removeEventListener的相关问题
- [转]Jollen 的 Android 教學,#16: Event Listener的用法: 以Click Listener為例