public static List<Challenge> getChallenges(EntityManager manager,
			String userMobileHash, int userRating, boolean listAll) {

		String condition = "= '" + userMobileHash + "'";
		if (listAll) {
			condition = " IS NULL";
		}
		Query query = manager.createQuery("select c from "
				+ Challenge.class.getName() + " c where c.max_rating >= "
				+ userRating + " AND c.opponent " + condition);
		List<Challenge> result = new LinkedList<Challenge>();
		for (Object obj : query.getResultList()) {
			if (obj instanceof Challenge) {
				Challenge challenge = (Challenge) obj;
				if (challenge.getMin_rating() <= userRating
						&& challenge.getMax_rating() >= userRating
						&& !challenge.getCreatedBy().equals(userMobileHash)) {
					result.add(challenge);
				}
			}
		}
		return result;
	}