java - how to create a hibernate projection that searches one column for any value = true -
java - how to create a hibernate projection that searches one column for any value = true -
i have hibernate entity type so
@entity @table(name = "type") public class type { @column(name = "enabled") private boolean enabled = false; }
and want create function returns if row in type table has enabled = true. want efficient possible using projection or criterion don't know start
maybe efficient way search first row has enabled = true
, , check if exists.
criteria crit = session.createcriteria(type.class); crit.setprojection(projections.id()); crit.add(restrictions.eq("enabled", true)); crit.setmaxresults(1); boolean anyisenabled = crit.uniqueresult() != null;
the query should homecoming result when/if encounters first result enabled = true
, doesn't have go through whole table solution using count
, example, have to.
java hibernate criteria hibernate-criteria
Comments
Post a Comment