Tuesday, 22 July 2014

How to exclude .svn folder in eclipse without subversion installed

1. Open Project Properties and Resource Filer as shown

image

2. Click Add Button

Select Filter type as “Exclude ALL” and Applies to “Folders” and Select “All Children” and Type .svn for File and Folder Attributes

image 


Click ok and now the .svn folder will not be listed in the Eclipse Explorer.

Thursday, 17 July 2014

Hibernate Criteria retrieve records when two fields are equal

Here is the code snippet from my project to retrieve the records when two field value in the  table has the same value.

if (laborderConditions.getBalanceStatus() != null) {
if (laborderConditions.getBalanceStatus().equalsIgnoreCase("Open")) {
criteria.add(Restrictions
.sqlRestriction("IFNULL(amount,0)=IFNULL(balance,0)"));
}

}

Wednesday, 9 July 2014

Hibernate Sort String field after changing to Integer

	Criteria criteria = getCurrentSession().createCriteria(LabOrder.class);

criteria.createAlias("practice", "pract", JoinType.INNER_JOIN);
criteria.createAlias("patient", "pat", JoinType.INNER_JOIN);
criteria.createAlias("labpanel", "panel", JoinType.LEFT_OUTER_JOIN);
criteria.addOrder(new org.hibernate.criterion.Order("orderNo", true) {
@Override
public String toSqlString(Criteria criteria,
CriteriaQuery criteriaQuery) throws HibernateException {
return "cast(orderNo as UNSIGNED) desc";
}
});

How to compare dates in hibernate using criteria if DB Field contains both Date and Time values

Here is the small code snippet from my current project to retrieve the records between two date. User will just enter the date part with year, month and date, but the DB Contains date and time value.

if (laborderConditions.getFromDOE() != null) {
criteria.add(Restrictions.ge("createdDate",
getFormattedFromDateTime(laborderConditions.getFromDOE())));
}

if (laborderConditions.getToDOE() != null) {
criteria.add(Restrictions.le("createdDate",
getFormattedToDateTime(laborderConditions.getToDOE())));
}




private Date getFormattedFromDateTime(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 0);
cal.set(Calendar.MINUTE, 0);
cal.set(Calendar.SECOND, 0);
return cal.getTime();
}

private Date getFormattedToDateTime(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.set(Calendar.HOUR_OF_DAY, 23);
cal.set(Calendar.MINUTE, 59);
cal.set(Calendar.SECOND, 59);
return cal.getTime();
}