Hibernate and Serializable Entities

后端 未结 1 641
挽巷
挽巷 2021-01-03 13:44

Does anyone know if there is a framework out there that is able to strip out Hibernate collections from entity classes to make them serializable? I had a look at BeanLib but

相关标签:
1条回答
  • 2021-01-03 14:08

    Dozer works well for this. Simply map the bean instance to a copy of itself.

    obj = dozerBeanMapper.map(obj, obj.getClass());
    

    In mapping the instance to a new instance, Dozer ignores whatever specific runtime implementation is used for the collections and instead uses the standard implementations or whatever your classes default to.

    I had a look at BeanLib but it only seems to do deep copies of entities while not allowing me to specify implementation mappings for the collection types in my entity classes.

    I'm curious, why does it matter what implementation is used for your collection types? As a best practice it's best for your persistent classes to refer to List, Set, etc., the actual implementations shouldn't matter to anyone who consumes these classes - they just care about the data.

    0 讨论(0)
提交回复
热议问题