Skip to content

Commit

Permalink
FORGE-1916: added handling for OptimisticLock exception
Browse files Browse the repository at this point in the history
  • Loading branch information
edewit authored and gastaldi committed Jul 1, 2014
1 parent 214b9b8 commit 74853c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.ws.rs.*;
Expand Down Expand Up @@ -83,7 +84,12 @@ public class ${entityTable}Endpoint
@Consumes("${contentType}")
public Response update(${entity.getName()} entity)
{
entity = em.merge(entity);
try {
entity = em.merge(entity);
} catch (OptimisticLockException e) {
return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build();
}

return Response.noContent().build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.OptimisticLockException;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import javax.ws.rs.*;
Expand Down Expand Up @@ -100,7 +101,11 @@ public class ${entityTable}Endpoint
entity = null;
}
entity = dto.fromDTO(entity, em);
entity = em.merge(entity);
try {
entity = em.merge(entity);
} catch (OptimisticLockException e) {
return Response.status(Response.Status.CONFLICT).entity(e.getEntity()).build();
}
return Response.noContent().build();
}
}

0 comments on commit 74853c4

Please sign in to comment.