Update DataServiceImpl.java

This commit is contained in:
Khurshid Fayzullaev 2014-04-10 15:32:04 -04:00
parent 6a30460996
commit f8bc5fb042

View File

@ -191,14 +191,15 @@ public class DataServiceImpl extends RemoteServiceServlet implements DataService
if (currentUser.getAdmin()) {
EntityManager entityManager = getSessionEntityManager();
synchronized (entityManager) {
String login = user.getLogin();
TypedQuery<User> query = entityManager.createQuery(
"SELECT x FROM User x WHERE x.login = :login", User.class);
query.setParameter("login", login);
List<User> results = query.getResultList();
entityManager.getTransaction().begin();
try {
String login = user.getLogin();
TypedQuery<User> query = entityManager.createQuery(
"SELECT x FROM User x WHERE x.login = :login", User.class);
query.setParameter("login", login);
List<User> results = query.getResultList();
if (results.isEmpty()) {
entityManager.persist(user);
entityManager.getTransaction().commit();