How can I get the first row of a table by using criteria
or HQL
query?
Table creation script
CREATE TABLE MonthlySubscriber(MSISDN bigint(20)
NOT NULL, MonthOfYear int(11) NOT NULL,
PRIMARY KEY (MSISDN));
Yes you can do that with setMaxResults
& setFirstResult
in criteria
Sample Code
Criteria queryCriteria = session.createCriteria(MonthlySubscriber.class);
queryCriteria.setFirstResult(0);
queryCriteria.setMaxResults(1);
monthlySubscriberList = queryCriteria .list();