Package es.mahulo.battleship.dao

Source Code of es.mahulo.battleship.dao.UserDaoImpl

package es.mahulo.battleship.dao;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import es.mahulo.battleship.api.dao.UserDao;
import es.mahulo.battleship.model.User;
@Repository
public class UserDaoImpl implements UserDao {
  private EntityManager entityManager;
  @PersistenceContext 
    public void setEntityManager(EntityManager entityManager)   { 
    this.entityManager = entityManager; 
   


  @Override
  @Transactional
  public User find(Long id) {
    return entityManager.find(User.class, id);
  }


  @Override
  public User findByName(String name) {
   
    Query q = entityManager.createQuery("SELECT u FROM User u WHERE u.name=:name",User.class);
    q.setParameter("name", name);

    User user = (User)q.getSingleResult();

    return user;
  }

}
TOP

Related Classes of es.mahulo.battleship.dao.UserDaoImpl

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.