user3364181
user3364181

Reputation: 541

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]

Upvotes: 2

Views: 320

Answers (2)

mtshaikh
mtshaikh

Reputation: 668

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

interface FilterMaxValues {

Integer getMaxBuyInFee();

Integer getMaxPrize();

Integer getMaxParticipants();

}

Upvotes: 1

sticky_elbows
sticky_elbows

Reputation: 1514

Don't you need to annotate your FilterMaxValues class with @Entity and @Table(name="yourDBTable") so that Spring can do the conversion for you automaticaly?

Upvotes: 0

Related Questions