Korki Korkig
Korki Korkig

Reputation: 2814

Hibernate transient field inside criteria

I have the field domainLevel1 which will be computed inside it's getter getDomainLevel1(). And I use this field inside criteria.

@Entity
@Table(name = "portal_bbc_budgetkey")
public class BudgetKey implements JsonSerializable {

    .....

    @Transient
    private String domainLevel1;

    public String getDomainLevel1() {
        return "BLABLABLABLA";
    }

    .....
}

public List<BudgetKey> findByWord() {
    Criteria criteria = sessionFactory.getCurrentSession()
                                      .createCriteria(BudgetKey.class);

    criteria.add(Restrictions.like("domainLevel1", "SEARCHME",MatchMode.ANYWHERE));

    return criteria.list(); // => EXCEPTION
}

But, findByWord() gives the following exception:

Caused by: 
          org.hibernate.QueryException: 
          could not resolve property: 
          domainLevel1 of: nl.xxx.BudgetKey

Am I allowed to use transient domainLevel1 inside the criteria or should I follow an another way to filter with a field which is not releated with a column( with criteria of course)?

Upvotes: 0

Views: 1338

Answers (1)

codeLover
codeLover

Reputation: 2592

It is because domainLevel1 is a transient variable and thus, is not mapped with any of the fields in table,thus you can't use it in Criteria

Upvotes: 1

Related Questions