All Downloads are FREE. Search and download functionalities are using the official Maven repository.

fi.foyt.fni.persistence.dao.common.CountryDAO Maven / Gradle / Ivy

There is a newer version: 3.3.13
Show newest version
package fi.foyt.fni.persistence.dao.common;

import javax.persistence.EntityManager;
import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;

import fi.foyt.fni.persistence.dao.GenericDAO;
import fi.foyt.fni.persistence.model.common.Country;
import fi.foyt.fni.persistence.model.common.Country_;

public class CountryDAO extends GenericDAO {

	private static final long serialVersionUID = 1L;

	public Country findByCode(String code) {
		EntityManager entityManager = getEntityManager();

    CriteriaBuilder criteriaBuilder = entityManager.getCriteriaBuilder();
    CriteriaQuery criteria = criteriaBuilder.createQuery(Country.class);
    Root root = criteria.from(Country.class);
    criteria.select(root);
    criteria.where(
  		criteriaBuilder.equal(root.get(Country_.code), code)
    );

    return getSingleResult(entityManager.createQuery(criteria));
	}

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy