Uploaded image for project: 'OpenJPA'
  1. OpenJPA
  2. OPENJPA-2188

metamodel generation with internal Map creates invalid metamodel

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.2.0
    • None
    • jpa
    • None

    Description

      import java.util.SortedMap;
      import java.util.TreeMap;
      
      import javax.persistence.Basic;
      import javax.persistence.ElementCollection;
      import javax.persistence.Entity;
      import javax.persistence.criteria.Path;
      import javax.persistence.criteria.Root;
      
      @Entity
      public final class BuggyMetamodel
      {
        enum Type
        {
          A,
          B,
          C;
        }
      
        protected static Path<SortedMap<Type, Integer>> pathMap1(
            final Root<BuggyMetamodel> root)
        {
          return root.<SortedMap<Type, Integer>>get(BuggyMetamodel_.map1);
        }
      
        protected static Path<SortedMap<Type, Integer>> pathMap2(
            final Root<BuggyMetamodel> root)
        {
          return root
              .<SortedMap<Type, SortedMap<String, Integer>>>get(BuggyMetamodel_.map2);
        }
      
        protected static Path<String> pathString(final Root<BuggyMetamodel> root)
        {
          return root.<String>get(BuggyMetamodel_.string);
        }
      
        @ElementCollection
        private final SortedMap<Type, Integer>                    map1   = new TreeMap<Type, Integer>();
      
        @ElementCollection
        private final SortedMap<Type, SortedMap<String, Integer>> map2   = new TreeMap<Type, SortedMap<String, Integer>>();
      
        @Basic
        private final String                                      string = "OpenJPA Rocks!";
      }
      

      nearly produces (minor change to remove "package ;" – see OPENJPA-2187)

      /** 
       *  Generated by OpenJPA MetaModel Generator Tool.
       **/
      
      import java.util.SortedMap;
      
      import javax.persistence.metamodel.MapAttribute;
      import javax.persistence.metamodel.SingularAttribute;
      
      @javax.persistence.metamodel.StaticMetamodel(value = BuggyMetamodel.class)
      @javax.annotation.Generated(value = "org.apache.openjpa.persistence.meta.AnnotationProcessor6", date = "Wed May 09 08:58:50 EDT 2012")
      public class BuggyMetamodel_
      {
        public static volatile MapAttribute<BuggyMetamodel, BuggyMetamodel.Type, Integer>   map1;
      
        public static volatile MapAttribute<BuggyMetamodel, BuggyMetamodel.Type, SortedMap> map2;
      
        public static volatile SingularAttribute<BuggyMetamodel, String>                    string;
      }
      

      which will not let BuggyMetamodel compile because:

      [INFO] -------------------------------------------------------------
      [ERROR] COMPILATION ERROR : 
      [INFO] -------------------------------------------------------------
      [ERROR] /workspace/project/src/main/java/BuggyMetamodel.java:[23,15] cannot find symbol
      symbol  : method <java.util.SortedMap<BuggyMetamodel.Type,java.lang.Integer>>get(javax.persistence.metamodel.MapAttribute<BuggyMetamodel,BuggyMetamodel.Type,java.lang.Integer>)
      location: interface javax.persistence.criteria.Root<BuggyMetamodel>
      [ERROR] /workspace/project/src/main/java/BuggyMetamodel.java:[30,8] cannot find symbol
      symbol  : method <java.util.SortedMap<BuggyMetamodel.Type,java.util.SortedMap<java.lang.String,java.lang.Integer>>>get(javax.persistence.metamodel.MapAttribute<BuggyMetamodel,BuggyMetamodel.Type,java.util.SortedMap>)
      location: interface javax.persistence.criteria.Root<BuggyMetamodel>
      [INFO] 2 errors 
      [INFO] -------------------------------------------------------------
      

      There's some fairly unreadable generic code going on, and I am not sure whether the reduction of SortedMap<String,Integer> to SortedMap without generic types is not a separate bug .... but either way, the metamodel generated classes are not usable in this configuration.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jieryn jieryn
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: