Quick revision
The short answer
With Panache's active record pattern, Order extends PanacheEntity and inherits findById, list and persist, so the resource is a @Path("/orders") class whose @GET @Path("/{id}") method returns Order.findById(id) and throws NotFoundException, or returns RestResponse.notFound(), when it is missing. Quarkus REST picks the thread from the method signature: a blocking return type such as Order runs on a worker thread, and Uni or Multi run on the event loop; @Blocking, @NonBlocking and @RunOnVirtualThread override that choice.
What to remember
In this answer, we wrote a Quarkus REST endpoint for GET /orders/{id}. The Order entity extends PanacheEntity and inherits findById, list and persist, and the resource returns Order.findById(id), with a NotFoundException or a RestResponse.notFound() for a missing order. Quarkus REST runs methods with plain return types on worker threads and methods returning Uni or Multi on the event loop, and @Blocking, @NonBlocking and @RunOnVirtualThread override that choice when the signature does not tell the truth.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
With Panache's active record pattern, Order extends PanacheEntity and inherits findById, list and persist, so the resource is a @Path("/orders") class whose @GET @Path("/{id}") method returns Order.findById(id) and throws NotFoundException, or returns RestResponse.notFound(), when it is missing. Quarkus REST picks the thread from the method signature: a blocking return type such as Order runs on a worker thread, and Uni or Multi run on the event loop; @Blocking, @NonBlocking and @RunOnVirtualThread override that choice.
Why this question is asked
A REST endpoint that reads one row is the hello world of every framework, and in Quarkus it is short enough to write from memory. What makes it a good interview question is the second half: Quarkus runs on an event loop underneath, and the same endpoint can run on very different threads depending on how we write it. Getting that wrong is how teams block the event loop or lose throughput. In this answer, we will write the Panache entity, write the resource, handle the missing case, and then see how Quarkus chooses between blocking, reactive and virtual-thread execution.
1A Quick Recap of Quarkus REST and Panache
Quarkus REST, previously called RESTEasy Reactive, is Quarkus's implementation of Jakarta REST (JAX-RS): we write classes with @Path and @GET as in any JAX-RS application. Under the hood it runs on Vert.x, which uses a few event loop threads for network I/O, plus a pool of worker threads for blocking code.
Panache is a layer on top of Hibernate ORM that removes most of the boilerplate of JPA. In the active record style, the entity class itself has static methods for queries, such as Order.findById(id), instead of a separate repository class. In the repository style, a class implementing PanacheRepository holds the same methods. Both work; this answer uses active record because the question asks for it.
2The Panache Entity
An entity extends PanacheEntity, which gives it a generated Long id field and all the query methods.
Notice that the fields are public. Panache rewrites access to public fields into getter and setter calls during the build, so Hibernate still sees proper accessors, and we can add a getter later without changing callers. Notice also the table name: an entity called Order would map to a table named order, which most databases reject because ORDER is a keyword.
3The Resource for GET /orders/{id}
The resource is a normal Jakarta REST class. Quarkus serialises the returned object to JSON when the quarkus-rest-jackson extension is present.
Without the null check, a missing order would make the method return null, and the response would be 204 No Content, which is misleading for a GET of one resource. NotFoundException is the standard Jakarta REST exception that maps to 404. If we prefer not to use exceptions for an expected case, Quarkus REST offers a typed response instead, shown in the next section.
4Returning RestResponse Instead of Throwing
RestResponse<T> is Quarkus REST's typed version of the JAX-RS Response. It keeps the body type visible in the signature, which helps documentation tools such as the OpenAPI generator.
Both styles are fine. Exceptions read well when "not found" is an error for the caller, and a shared exception mapper can add a problem-details body. RestResponse reads well when several statuses are normal outcomes of the same method.
5How Quarkus Chooses the Thread
This is the part to understand well. Quarkus REST looks at each method's signature during the build. If the method returns a plain type such as Order or RestResponse<Order>, Quarkus assumes it may block, for example on JDBC, and dispatches it to a worker thread. If it returns Uni<Order> or Multi<Order>, the reactive types from the Mutiny library, Quarkus assumes it is non-blocking and runs it directly on the event loop, which is cheaper because there is no thread switch.
Our Order.findById(id) uses Hibernate ORM over JDBC, which blocks, so the plain signature and the worker thread are exactly right. A reactive version uses Hibernate Reactive with Panache, whose findById returns a Uni and never blocks; it then runs on the event loop. Reactive Panache needs a session or transaction around the call, given by annotations such as @WithSession or @WithTransaction; check your version for when these are implied.
- @RunOnVirtualThread present?YesRun on a new virtual threadNoLook at other annotations
- @Blocking or @NonBlocking present?YesUse what the annotation saysNoLook at the return type
- Returns Uni, Multi or CompletionStage?YesRun on the event loopNoRun on a worker thread
3 steps in order. Play them, or step through them one at a time.
Our plain Order method lands on a worker thread, which suits blocking JDBC.
The overrides exist because the signature is only a guess. @Blocking is needed when a method returns Uni but calls something blocking inside. @NonBlocking is for a plain method that we know never blocks, such as returning a constant. @RunOnVirtualThread runs a blocking-style method on a virtual thread instead of a worker, so thousands of concurrent requests can wait on I/O without thousands of platform threads. Virtual threads have their own caveats, such as pinning in some libraries and pool sizes that must still limit database connections, so measure before switching.
6Follow-up questions
What happens if a blocking call runs on the event loop?
Every other request served by that event loop thread waits until the call returns, so latency rises for unrelated requests. Vert.x detects long-running tasks and logs a blocked-thread warning, and Quarkus refuses some obviously blocking operations on the event loop with an error. The fix is to use the right signature, add @Blocking, or switch to the reactive client.
Why is persist() only allowed in a transaction?
With Hibernate ORM, changes are written when the transaction commits, so a persist outside a transaction has nothing to flush it, and Quarkus raises an error. We put @Transactional on the resource method or on a service method that writes. Reads such as findById work without an explicit transaction.
Active record or repository: which would you choose?
Active record is compact and fine for small services where entities are simple. The repository style keeps queries out of the entity, is easier to mock in unit tests, and feels familiar to Spring Data users. Large teams often prefer repositories for that separation; Panache supports both with the same methods.
7Conclusion
In this answer, we wrote a Quarkus REST endpoint for GET /orders/{id}. The Order entity extends PanacheEntity and inherits findById, list and persist, and the resource returns Order.findById(id), with a NotFoundException or a RestResponse.notFound() for a missing order. Quarkus REST runs methods with plain return types on worker threads and methods returning Uni or Multi on the event loop, and @Blocking, @NonBlocking and @RunOnVirtualThread override that choice when the signature does not tell the truth.
Open with
I'd make Order a Panache entity: annotate it with @Entity, map it to a table called orders because ORDER is a reserved word, and extend PanacheEntity, which gives it a Long id and static methods like findById, list and persist.
Then, if they want more
The resource is a normal Jakarta REST class: @Path orders, and a method with @GET and @Path of id that takes the id as a @PathParam Long, calls Order.findById, and throws NotFoundException if it's null, otherwise returns the order, which Jackson turns into JSON. Alternatively I can return RestResponse of Order, with RestResponse.notFound or ok.
On threading, Quarkus REST decides from the signature at build time. A method returning a plain type like Order is treated as possibly blocking and runs on a worker thread, which is right here because Hibernate ORM uses blocking JDBC.
A method returning Uni or Multi is treated as non-blocking and runs on the event loop, which is what I'd use with Hibernate Reactive Panache.
If the signature lies, I override it: @Blocking forces a worker, @NonBlocking forces the event loop, and @RunOnVirtualThread runs a blocking method on a virtual thread, which helps with very high concurrency on Java 21 and later.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Java 21
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the official documentation for the version you use. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Write a Quarkus REST endpoint GET /orders/{id} that returns an Order from a Panache...": https://scrivio-interview-library.netlify.app/java/other-java-frameworks/db5f02a4c6/