OpenJPA
  1. OpenJPA
  2. OPENJPA-2188

metamodel generation with internal Map creates invalid metamodel

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.2.0
    • Fix Version/s: None
    • Component/s: jpa
    • Labels:
      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.

        Activity

        Hide
        jieryn added a comment -

        Even when I change BuggyMetamodel.java to:

          protected static Path<SortedMap> pathMap1(final Root<BuggyMetamodel> root)
          {
            return root.<SortedMap>get(BuggyMetamodel_.map1);
          }
        
          protected static Path<SortedMap> pathMap2(final Root<BuggyMetamodel> root)
          {
            return root.<SortedMap<Type, SortedMap>>get(BuggyMetamodel_.map2);
          }
        

        I still take compilation errors. So I don't think this is a generics issue, at least in an obvious way..

        Show
        jieryn added a comment - Even when I change BuggyMetamodel.java to: protected static Path<SortedMap> pathMap1( final Root<BuggyMetamodel> root) { return root.<SortedMap>get(BuggyMetamodel_.map1); } protected static Path<SortedMap> pathMap2( final Root<BuggyMetamodel> root) { return root.<SortedMap<Type, SortedMap>>get(BuggyMetamodel_.map2); } I still take compilation errors. So I don't think this is a generics issue, at least in an obvious way..

          People

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

            Dates

            • Created:
              Updated:

              Development