What you are trying to do is theoretically correct and should work. Nevertheless, I am thinking of some possible things that may prove to be wrong:
Make sure your getter and setter are properly used. Your code should look like:
private boolean viewed; @Type(type = "true_false") @Column(name = "Viewed") public boolean isViewed() { return viewed; } public void setViewed(boolean viewed) { this.viewed = viewed; }
Make sure your DB field is a
BIT
(or the corresponding data type for boolean values on the DB you are using).If neither 1 nor 2 work, I suggest removing the
@Type
annotation as it is not necessary, although it should do no harm.
Edit:
You are trying to map a boolean
to a char
. I do not really understand why you would use a char(1)
instead of a BIT
. Nevertheless, if you want to do so, work with a String
in the model class.
Then, if your DB column holds 0 or 1, use:
criteria.add(Restrictions.eq("participants.viewed", "0"));
Or if your DB column holds true/false, use:
criteria.add(Restrictions.eq("participants.viewed", "false"));