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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -