These are chat archives for hibernate/hibernate-orm

27th
May 2018
Marc Guilera
@marcguilera
May 27 21:45
I'm trying to do a count on a field on an H2 DB and I'm getting a org.hibernate.QueryException: could not resolve property: Bonus of: com.marc.casumo.rent.backend.dal.rentals.RentalConfig(the config being the entity)

the rental entity looks like this however:

package com.marc.casumo.rent.backend.dal.rentals;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.marc.casumo.rent.backend.dal.shared.ConfigBase;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import java.util.Date;

@Entity
@Table(name = "Rental")
public class RentalConfig extends ConfigBase {
    @Column(name = "FilmID", nullable = false)
    @NotNull
    @JsonProperty
    private Long filmId;

    @Column(name = "UserID", nullable = false)
    @NotNull
    @JsonProperty
    private Long userId;

    @Column(name = "Bonus", nullable = false)
    @NotNull
    @JsonProperty
    private Long bonus = 0L;

    @Column(name = "Price", nullable = false)
    @NotNull
    @JsonProperty
    private Float price = 0F;

    @Column(name = "StartDate", nullable = false)
    @NotNull
    @JsonProperty
    private Date startDate;

    @Column(name = "EndDate", nullable = false)
    @NotNull
    @JsonProperty
    private Date endDate;

    public Long getFilmId() {
        return filmId;
    }

    public void setFilmId(Long filmId) {
        this.filmId = filmId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getBonus() {
        return bonus;
    }

    public void setBonus(Long bonus) {
        this.bonus = bonus;
    }

    public Float getPrice() {
        return price;
    }

    public void setPrice(Float price) {
        this.price = price;
    }

    public Date getStartDate() {
        return startDate;
    }

    public void setStartDate(Date startDate) {
        this.startDate = startDate;
    }

    public Date getEndDate() {
        return endDate;
    }

    public void setEndDate(Date endDate) {
        this.endDate = endDate;
    }
}

I'm querying like this:

Object result = criteria()
                    .add(eq(USER_ID, userId))
                    .setProjection(sum(BONUS))
                    .uniqueResult();
            return result == null
                    ? 0L
                    : (Long) result;
any ideas?
private static final String USER_ID = "UserID";
private static final String BONUS = "Bonus";