HQL: Using Boolean in Named Queries

Jemru picture Jemru · Jan 5, 2012 · Viewed 40.2k times · Source

Can you please help me? I have error in querying boolean value "r.isDefault = true".

In my HQL named query:

<named-query name="RptQuery.queryDefaultByCode">
    <query>
        SELECT r FROM RptQuery r WHERE r.code = ?1 AND r.isDefault = true
    </query>
</named-query>

I get error: Caused by: org.hibernate.HibernateException: Errors in named queries: RptQuery.queryDefaultByCode

In my persistence.xml:

<property name="hibernate.query.substitutions" value="true='Y', false='N', yes='Y', no='N'"/>

In my pojo:

private boolean isDefault;

@Column(name = "CPMN_IS_DEFLT", length = 1)
@Type(type = "yes_no")
public boolean isDefault() {
    return this.isDefault;
}

public void setDefault(boolean isDefault) {
    this.isDefault = isDefault;
}

Thank you in advance!

Answer: Just found a minor error:

r.isDefault = true

should be

r.default = true

Thanks.

Answer

giannisapi picture giannisapi · Apr 26, 2012

try this : where r.isDefault is true