[
https://issues.jboss.org/browse/FORGE-1212?page=com.atlassian.jira.plugin...
]
George Gastaldi closed FORGE-1212.
----------------------------------
Assignee: George Gastaldi
Fix Version/s: 1.4.2.Final
Resolution: Done
Fixed
REST endpoint findById doesn't handle NoResultException
-------------------------------------------------------
Key: FORGE-1212
URL:
https://issues.jboss.org/browse/FORGE-1212
Project: Forge
Issue Type: Bug
Affects Versions: 1.4.1.Final
Reporter: Antonio Goncalves
Assignee: George Gastaldi
Fix For: 1.4.2.Final
When a REST endpoint is generated the {{findById}} method looks like this :
{code}
@GET
@Path("/{id:[0-9][0-9]*}")
@Produces("application/xml")
public Response findById(@PathParam("id") Long id) {
TypedQuery<Book> findByIdQuery = em.createQuery("SELECT DISTINCT b
FROM Book b WHERE b.id = :entityId ORDER BY b.id", Book.class);
findByIdQuery.setParameter("entityId", id);
Book entity = findByIdQuery.getSingleResult();
if (entity == null) {
return Response.status(Status.NOT_FOUND).build();
}
return Response.ok(entity).build();
}
{code}
The problem is that when the entity doesn't exist, the
{{findByIdQuery.getSingleResult()}} doesn't return {{null}} but throws a
{{NoResultException}}. So the {{if (entity == null)}} is never reached.
The generated code should catch the {{NoResultException}} and return the {{return
Response.status(Status.NOT_FOUND)}}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see:
http://www.atlassian.com/software/jira