How to set true or false if there is no record in table using hibernate <p>I am using Spring REST with Hibernate and i am fetching a particular record from database table passing id into my method. The method is working properly but if there is no record in table then i want false in a variable and if record exist then i want true in the variable in my json object.</p> <p>Here is my Entity class <strong>Subscribe.java</strong></p> <pre><code>@Entity @Table(name="subscribe") @JsonIgnoreProperties({"hibernateLazyInitializer", "handler"}) public class Subscribe implements Serializable { private static final long serialVersionUID = 1L; @Id @GeneratedValue @Column(name="id") private long id; @Column(name="subscribed_id") private String subID; @Column(name="subscriber_id") private long subrID; public long getSubrID() { return subrID; } public void setSubrID(long subrID) { this.subrID = subrID; } public String getSubID() { return subID; } public void setSubID(String subID) { this.subID = subID; } public long getId() { return id; } public void setId(long id) { this.id = id; } } </code></pre> <p>Here is my <strong>DAO</strong> class</p> <pre><code>@SuppressWarnings({ "unchecked", "rawtypes" }) public List&lt;Subscribe&gt; getSubscribeById(long id) throws Exception { session = sessionFactory.openSession(); Criteria cr = session.createCriteria(Subscribe.class); cr.add(Restrictions.eq("subrID", id)); List results = cr.list(); tx = session.getTransaction(); session.beginTransaction(); tx.commit(); return results; } </code></pre> <p>And here is my <strong>Controller</strong></p> <pre><code> @RequestMapping(value = "/subscribe/{id}", method = RequestMethod.GET) public @ResponseBody List&lt;Subscribe&gt; getSubscriber(@PathVariable("id") long id) { List&lt;Subscribe&gt; sub = null; try { sub = profileService.getSubscribeById(id); } catch (Exception e) { e.printStackTrace(); } return sub; } </code></pre> <p>Please suggest me how can can i do this</p>