如何正确地序列化Hibernate集合? [英] How to Serialize Hibernate Collections Properly?

查看:184
本文介绍了如何正确地序列化Hibernate集合?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图序列化数据库中已用Hibernate检索的对象,我只对整个对象的实际数据感兴趣(包括循环)。

I'm trying to serialize objects from a database that have been retrieved with Hibernate, and I'm only interested in the objects' actual data in its entirety (cycles included).

现在我一直在使用 XStream ,这看起来很强大。 XStream的问题是它看起来太盲目的信息。它识别Hibernate的PersistentCollections,就像包含所有Hibernate元数据一样。我不想序列化这些。

Now I've been working with XStream, which seems powerful. The problem with XStream is that it looks all too blindly on the information. It recognizes Hibernate's PersistentCollections as they are, with all the Hibernate metadata included. I don't want to serialize those.

所以,有一个合理的方法从一个PersistentCollection中提取原始的集合,并初始化所有引用数据对象可能指向。

So, is there a reasonable way to extract the original Collection from within a PersistentCollection, and also initialize all referring data the objects might be pointing to. Or can you recommend me to a better approach?

(结果来自简单似乎完美,但它不能处理像日历这样的基本util类,它也只接受一个注释对象一次)

(The results from Simple seem perfect, but it can't cope with such basic util classes as Calendar. It also accepts only one annotated object at a time)

推荐答案

解决方案对我来说很好: http:// jira.codehaus.org/browse/XSTR-226

solution described here worked well for me: http://jira.codehaus.org/browse/XSTR-226

这个想法是为hibernate集合提供自定义XStream转换器/ mapper,这将从hibernate一个,并将调用相应的标准转换器(对于ArrayList,HashMap等)

the idea is to have custom XStream converter/mapper for hibernate collections, which will extract actual collection from hibernate one and will call corresponding standard converter (for ArrayList, HashMap etc.)

这篇关于如何正确地序列化Hibernate集合?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆