Details
-
Bug
-
Status: In Progress
-
Should
-
Resolution: Unresolved
-
1.7.0
-
None
-
None
-
Low
-
Description
Intro
In JPA you can map one-to-may relation as Java collection.
...
@javax.persistence.OneToMany()
private List<RelatedEntity> relatedEntities;
...
Hibernate will manage the object for this field, it will be an object of some Hibernate class.
In case of List, it can be org.hibernate.collection.internal.PersistentList or org.hibernate.collection.internal.PersistentBag. The 'bag' variant is considered as optimization on Hibernate side.
Bug
The built-in implementations of org.openmrs.module.metadatasharing.serializer.converter.CollectionConverterCompatibility doesn't support PersistentBag.
It leads to StackOverflowException.
Since all of these PersistentCollections implement regular List/Set/Map interfaces, I would suggest rely on these interfaces in determining what 'regular java collection' to convert to.
@Override public void marshal(Object source, HierarchicalStreamWriter writer, MarshallingContext context, ConverterLookup converterLookup) { if (source instanceof PersistentList) { source = new ArrayList((Collection) source); } else if (source instanceof PersistentMap) { source = new HashMap((Map) source); } else if (source instanceof PersistentSortedMap) { source = new TreeMap((SortedMap) source); } else if (source instanceof PersistentSortedSet) { source = new TreeSet((SortedSet) source); } else if (source instanceof PersistentSet) { source = new HashSet((Set) source); } // delegate the collection to the appropriate converter converterLookup.lookupConverterForType(source.getClass()).marshal(source, writer, context); }