Getting @Transactional to work with Quarkus Websockets

Issue


Issue as of 2023-07-26.

Panache entities transactions fail on websocket even with @Transaction annotated on endpoint with error BlockingOperationNotAllowedException: Cannot start a JTA transaction from the IO thread in the following code.

@Transactional
@OnMessage
public void onMessage(String message) {
  // example transaction stuff...
  var exampleitem = new ExampleItem();
  exampleitem.persist();
}

Fix


The websocket needs to be configured to dispatch to a worker thread.

# src/main/resources/application.properties

# add following line
quarkus.websocket.dispatch-to-worker = true

Hope this is helpful to you.