开发者

Refresh of an Entity with a colllection throws a UnresolvableObjectException when an Element of the collection got deleted

We have a two tier Swing application using Hibernate. Sometimes we manipulate an object in one session (A), which we know in another session (B) as well (two different Java Instances, same database record).

In this case after commit and closing of A, we refresh the object in session B, in order to show the updated state in the UI. Works fine in most of the cases.

But if we have an object X with a collection of Ys we get a problem with the follow开发者_如何学Going sequence of events:

B: load X and Ys

A: load X and Ys

A: remove one Y from the collection and the database

A: flush, commit and close the session

B: refresh X

At the last step we get a UnresolvableObjectException which seems to happen, because B the X keeps its collection (instead to refreshing the collection itself) and tries to refresh each contained instance of Y which of course fails when reaching the deleted one.

If found problem descriptions about similar problems when refreshing collections, but

  • no solution

  • no bug report

  • no explanation, that this is by design

So these are my questions: How can I solve my problem (Even a pointer into the source code with a post it 'fix here' would be of help)? Is this a bug? If so, is it a known one?


Yes, it is exactly like this. I can reproduce this error, too. In my opinion it is an error in Hibernate.

What you can do is: Use

session.evict(X);
session.load(X, primaryKeyOfX);

instead of session.refresh(X) in thread B. Then it works.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜