Search code examples
javahibernatespring-bootspring-data-jpahql

Convert result from HQL into Object


This is my method in repository class :

@Query("select max(entry_fee) as maxBuyInFee, max(prize) as maxPrize, max(participants_number) as maxParticipants from Tournament tournament")
    FilterMaxValues findFilterMaxValues();

And this is my FilterMaxValues class :

public class FilterMaxValues {

    private Integer maxBuyInFee;

    private Integer maxPrize;

    private Integer maxParticipants;

How can i convert result from this HQL into FilterMaxValues object ?

Now i get :

No converter found capable of converting from type [java.util.HashMap] to type [com.test.FilterMaxValues]


Solution

  • You could use projections if your FilterMaxValues is not an entity, like

    interface FilterMaxValues {
    
    Integer getMaxBuyInFee();
    
    Integer getMaxPrize();
    
    Integer getMaxParticipants();
    
    }