Uploaded image for project: 'Metadata Sharing Module'
  1. Metadata Sharing Module
  2. META-377

PersistentBag not supported by CollectionConverterCompatibility

    XMLWordPrintable

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);
      }

      Gliffy Diagrams

        Attachments

          Activity

            People

              wolterbwambale Benny wolter Bwambale
              pwargulak Piotr Wargulak
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

                Created:
                Updated: