Spring Data JPA
  1. Spring Data JPA
  2. DATAJPA-45

ClassCastException on getReturnedDomainClass for parametrized types

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Core
    • Labels:
      None

      Description

      ClassCastException on getReturnedDomainClass for parametrized types.

      The query:

       @NamedQuery(name = "ContentFlag.getNewFlagCountByReasonForTitleId", query = "select new map ( c.reason as reason, count(*) as numFlags ) "
                      + "from ContentFlag c where c.content.title.id = ?1"
                      + " and (c.dateFlagSet > c.content.statistics.dateFlagCleared or c.content.statistics.dateFlagCleared is null) "
                      + "group by c.reason")
      
      

      The method:

      public abstract java.util.List com.qualcomm.qis.plaza.repo.ContentFlagRepository.getNewFlagCountByReasonForTitleId(java.lang.Long)
      

      The actual return type:

      java.util.List<java.util.Map<java.lang.String, java.lang.Object>>
      

      The line where the exception is thrown:

      return (Class<?>) ((ParameterizedType) type)
                          .getActualTypeArguments()[0];
      

      The exception:

      Caused by: java.lang.ClassCastException: sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class
      	at org.springframework.data.repository.util.ClassUtils.getReturnedDomainClass(ClassUtils.java:63)
      	at org.springframework.data.repository.query.QueryMethod.getDomainClass(QueryMethod.java:107)
      	at org.springframework.data.jpa.repository.query.JpaQueryMethod.getNamedQueryName(JpaQueryMethod.java:126)
      	at org.springframework.data.jpa.repository.query.NamedQuery.lookupFrom(NamedQuery.java:71)
      	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$DeclaredQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:132)
      	at org.springframework.data.jpa.repository.query.JpaQueryLookupStrategy$AbstractQueryLookupStrategy.resolveQuery(JpaQueryLookupStrategy.java:73)
      	at org.springframework.data.repository.support.RepositoryFactorySupport$QueryExecuterMethodInterceptor.<init>(RepositoryFactorySupport.java:259)
      	at org.springframework.data.repository.support.RepositoryFactorySupport.getRepository(RepositoryFactorySupport.java:143)
      	at org.springframework.data.repository.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:107)
      	at org.springframework.data.repository.support.RepositoryFactoryBeanSupport.getObject(RepositoryFactoryBeanSupport.java:36)
      	at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:142)
      	... 36 more
      
      

        Activity

        Hide
        Oliver Gierke added a comment -

        Should be fixed with the latest Spring Data Commons release.

        Show
        Oliver Gierke added a comment - Should be fixed with the latest Spring Data Commons release.

          People

          • Assignee:
            Oliver Gierke
            Reporter:
            Andres March
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: