I have two entity: Issue
and Issue_Tracker
. I am using Hibernate 3.6.
SELECT `issues`.`issue_id`,
`issues`.`issue_raised_date`,
`issues`.`issue_description`,
`issue_tracker`.`tracker_status`
FROM `issues`
LEFT JOIN `issue_tracker` ON `issues`.`issue_id` = `issue_tracker`.`issue_id`
WHERE `issues`.`status`="Escalate To"
How to achieve this using Hibernate Criteria, and most Important, I have to use it for pagination.
and My Dao is as follows to show the list of Issues in jqgrid
public List showHelpDeskIssues(DetachedCriteria dc, int from, int size) {
Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { Criteria criteria = dc.getExecutableCriteria(session); criteria.setFirstResult(from); criteria.setMaxResults(size); criteria.add(Restrictions.eq("status","Escalate To")); return criteria.list(); } catch (HibernateException e) { e.printStackTrace(); throw e; } }
For brief explanation please refer this question how to show two tables data in jqgrid using struts2 - jqgrid plugin and hibernate any help would be great.
you can try the following
Criteria criteria = session.createCriteria(Issues.class);
criteria.setFirstResult(from);
criteria.setMaxResults(size);
criteria.setFetchMode('parent.child', FetchMode.JOIN);
criteria.add(Restrictions.eq("status", "Escalate To");
List<Issues> list= criteria.list();
here parent is the property name in Issues.java
and child is the property in IssueTracker.java
.
Well,
follow one sample...
Criteria crit = session.createCriteria(Issues.class);
crit.createAlias("otherClass", "otherClass");
crit.add(Restrictions.eq("otherClass.status", "Escalate To"));
List result = crit.list();
I think so this can to help!!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With