class HibernateContactDAO extends HibernatePersistentObjectDAO<Contact> implements ContactDAO {

	@Override
	public List<Contact> findByUser(Long userId, String email) {
		List<Object> params = new ArrayList<Object>();
		if (userId != null)
			params.add(userId);
		if (email != null)
			params.add(email);

		StringBuffer sb = new StringBuffer("");
		if (userId == null)
			sb.append(" _entity.userId is null ");
		else
			sb.append(" _entity.userId = ?1 ");
		if (email != null)
			sb.append(" and _entity.email = ?2 ");

		try {
			return findByWhere(sb.toString(), params.isEmpty() ? null : params.toArray(new Object[0]),
					"order by _entity.firstName, _entity.lastName", null);
		} catch (PersistenceException e) {
			log.error(e.getMessage(), e);
			return new ArrayList<Contact>();
		}
	}

	public  HibernateContactDAO();

}