How to Serialize Hibernate Collections Properly?

后端 未结 3 2075
时光取名叫无心
时光取名叫无心 2020-12-17 06:37

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 inclu

3条回答
  •  长情又很酷
    2020-12-17 07:09

    I recommend a simpler approach: user dozer: http://dozer.sf.net. Dozer is a bean mapper, you can use it to convert, say, a PersonEJB to an object of the same class. Dozer will recursively trigger all proxy fecthes through getter() calls, and will also convert src types to dest types (let's say java.sql.date to java.utilDate).

    Here's a snippet:

    MapperIF mapper = DozerBeanMapperSingletonWrapper.getInstance();
    PersonEJB serializablePerson = mapper.map(myPersonInstance, PersonEJB.class);
    

    Bear in mind, as dozer walks through your object tree it will trigger the proxy loading one by one, so if your object graph has many proxies you will see many queries, which can be expensive.

提交回复
热议问题