开发者

Hibernate and serialization

In our application we have a dual persistence. First, the 开发者_开发技巧entity can be saved online in a MySQL DB (we are using Hibernate), second the entity can be saved locally through serialization.

The entity I'm speaking of is an object of the class User which contains a KnowledgeBase object and that KnowledgeBase contains two lists of entities (List<Card> and List<Deck>).

Both persistences work fine in separate, but there are problems when I try to de-serialize a serialized User object that I loaded from the database, i.e. that has been trough Hibernate at least once (well, twice, actually).

What I've noticed is the the ArrayList inside KnowledgeBase are replaced by PersistentBag. Could that that be the source of my problem?

Another guess might be that lazy loading causes these troubles... Is there a way to tell Hibernate to fully load an object at some point? (Apart from eager loading...)


Yes, Hibernate.initialize(..) initializes objects and collections.

Then, if needed, you can replace the collections with the regular java.util ones using the copy-constructor: setList(new ArrayList(list))

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜