Home > Software engineering >  Arbitrary selection
Arbitrary selection

Time:01-01

@Query("select clusters.id, "  
        "sum(greatest(frequencies.january, "  
        "frequencies.february, "  
        "frequencies.march, "  
        "frequencies.april, "  
        "frequencies.may, "  
        "frequencies.june, "  
        "frequencies.july, "  
        "frequencies.august, "  
        "frequencies.september, "  
        "frequencies.october, "  
        "frequencies.november, "  
        "frequencies.december)) summedFrequency "  
        "from ClusterEntity clusters "  
        "left join PhraseEntity phrases on phrases.cluster.id=clusters.id "  
        "left join FrequencyEntity frequencies on frequencies.phrase.id=phrases.id "  
        "where clusters.page.id = :page_id "  
        "group by clusters.id "
)
List<ClusterEntity> findAllClustersByPage(@Param("page_id") Integer pageId);

This method definitely will not return a list of ClusterEntity.

Could you tell what to return when I execute some arbitrary query as in this case.

CodePudding user response:

Yes, It definitely won't be ClusterEntity. I don't know the structure of your ClusterEntity but it seems you are trying to retrieve multiple columns from your table as per your @Query statement. If that's true then by default it returns List<Object[]> and to obtain the result cast it to a specific type, you can find more info here, if not then please be more specific.

How to get multiple columns from table using JPA?

  • Related