hibernate query to get the first data

HibernateTransactionManager transactionManager = (HibernateTransactionManager)applicationContext.getBean("transactionManager");
List<Shipment> shipments =  null;
String hql = "from Shipment s where (s.status>:status OR s.status<:status)" +
		" AND s.gpsTerminalDevice.id =:gpsID ORDER BY s.leaveTime DESC";
try {
	Session session = transactionManager.getSessionFactory().getCurrentSession();
	Query query = session.createQuery(hql);
	query.setString("status", ShipmentStatus.CANCEL);
	query.setLong("gpsID", gpsTerminalDevice.getId());
	shipments = query.setFirstResult(0).setMaxResults(1).list();
}  catch (Exception e) {
	e.printStackTrace ();
	throw new BusinessException(e.getLocalizedMessage());
}

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327045381&siteId=291194637