开发者

Refreshing entity instance after using merge in hibernate?

开发者 https://www.devze.com 2023-01-13 15:30 出处:网络
am using hibernate merge method, to deal with detached instance from entity, and i though开发者_如何学Got that the return of this method will be a new fetched instance from database as hibernate saveO

am using hibernate merge method, to deal with detached instance from entity, and i though开发者_如何学Got that the return of this method will be a new fetched instance from database as hibernate saveOrUpdate method, but that wasn't the case, and i think it's logic as it's a detached instance, so is there a better way to return the new instance rather than using findById,

regards,


The merge method copies the state of the passed object to a persistent entity with the same identifier (that is either already associated with the session or will be loaded) and then return a reference to that persistent entity. The object passed as parameter is not attached to the session.

So unless I didn't understand the question, I think you should do something like this:

Foo mergedFoo = session.merge(foo);
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号