package dao.jpa;
import dao.DataAccessException;
import dao.UserRoleDao;
import models.entities.UserRole;
import play.Logger;
import play.db.jpa.JPA;
import javax.persistence.TypedQuery;
/**
* Created by kiryl on 17.08.2014.
*/
public class UserRoleJpaDao extends BaseJpaDao<UserRole, Integer> implements UserRoleDao {
@Override
public UserRole findByName(String roleName) throws DataAccessException {
if (roleName == null) {
return null;
}
try {
TypedQuery<UserRole> query = JPA.em().createQuery("SELECT r FROM UserRole r WHERE r.name = :roleName", UserRole.class);
query.setParameter("roleName", roleName);
return query.getSingleResult();
} catch (Throwable throwable) {
Logger.error("Failed to get role by name: " + roleName);
throw new DataAccessException("Failed to get role by name: " + roleName, throwable);
}
}
}