quarkusio/quarkus · error · NoResultException
No Country found with id =
Error message
No Country found with id =
What it means
CountryResource.editIso3 looks up a Country by id via countryRepository.findById; when the Optional is empty it throws javax.persistence.NoResultException('No Country found with id =' + id). This emulates Spring Data's getOne/getReference behavior where updating a non-existent row raises NoResultException.
Source
Thrown at integration-tests/spring-data-jpa/src/main/java/io/quarkus/it/spring/data/jpa/CountryResource.java:67
@GET
@Path("/new/{name}/{iso3}")
@Produces("application/json")
public Country newCountry(@PathParam("name") String name, @PathParam("iso3") String iso3) {
countryRepository.flush();
return countryRepository.saveAndFlush(new Country(name, iso3));
}
@GET
@Path("/editIso3/{id}/{iso3}")
@Produces("application/json")
public Country editIso3(@PathParam("id") Long id, @PathParam("iso3") String iso3) {
Optional<Country> optional = countryRepository.findById(id);
if (optional.isPresent()) {
Country country = optional.get();
country.setIso3(iso3);
return countryRepository.save(country);
} else {
throw new NoResultException("No Country found with id =" + id);
}
}
@GET
@Path("/getOne/{id}")
@Produces("application/json")
public Country getOne(@PathParam("id") Long id) {
return countryRepository.getOne(id);
}
@DELETE
@Path("/")
public void deleteAllInBatch() {
this.countryRepository.deleteAllInBatch();
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Verify the Country id exists (GET the resource or check the DB) before editing
- Handle NoResultException with an ExceptionMapper returning 404 Not Found
- Use PUT semantics that create-or-update (upsert) if that matches your contract
Example fix
// before
} else {
throw new NoResultException("No Country found with id =" + id);
}
// after
} else {
return Response.status(Response.Status.NOT_FOUND)
.entity("No Country found with id " + id).build();
} Defensive patterns
Strategy: validation
Validate before calling
boolean exists = countryRepository.findById(id).isPresent();
if (!exists) {
// surface 404 before attempting editIso3
}
Try / catch
try {
countryResource.editIso3(id, iso3);
} catch (NoResultException e) {
// handle as 404: entity with given id does not exist
} Prevention
- Confirm ids exist (fresh fetch, not cached client state) before updates
- Register an ExceptionMapper turning NoResultException into HTTP 404
- Seed fixtures before update calls in tests
When it happens
Trigger: PUT/POST to the edit-iso3 endpoint with an id that has no corresponding row in the Country table.
Common situations: Stale client holding an id deleted elsewhere; test fixtures not seeded before update calls; integer-vs-string id mismatches in path parameters.
Understand the failure class
Background: "Not found" and "does not exist" errors: why "Task not found", "No such folder", and "Can't find" fire when a lookup comes back empty — this error's family across 14 libraries.
Related errors
- There is already an active cart
- no Person found with name =
- Distinct is not yet supported. Offending method is ${reposit
- A field must by supplied after 'OrderBy' . Offending method
- Field ${orderField} which was configured as the order field
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/75b7e87a370be603.
Report an issue: GitHub.