quarkusio/quarkus · error · IllegalStateException
Not supported for transaction scoped entity managers
Error message
Not supported for transaction scoped entity managers
What it means
A transaction-scoped session is created and destroyed per transaction/invocation and is managed by Quarkus; the user must never close it manually. Calling close() therefore throws IllegalStateException.
Source
Thrown at extensions/hibernate-orm/runtime/src/main/java/io/quarkus/hibernate/orm/runtime/session/TransactionScopedStatelessSession.java:286
}
@Override
public void joinTransaction() {
try (SessionResult emr = acquireSession()) {
emr.statelessSession.joinTransaction();
}
}
@Override
public boolean isJoinedToTransaction() {
try (SessionResult emr = acquireSession()) {
return emr.statelessSession.isJoinedToTransaction();
}
}
@Override
public void close() {
throw new IllegalStateException("Not supported for transaction scoped entity managers");
}
@Override
public Object insert(Object o) {
checkBlocking();
try (SessionResult emr = acquireSession()) {
return emr.statelessSession.insert(o);
}
}
@Override
public Object insert(String s, Object o) {
checkBlocking();
try (SessionResult emr = acquireSession()) {
return emr.statelessSession.insert(s, o);
}
}
View on GitHub (pinned to e1c734241f)
Solutions
- Remove the close() call — Quarkus closes the transaction-scoped session automatically
- Scope the work with @Transactional instead of manual session lifecycle management
- Use a manual (application-managed) session via entityManagerFactory().createEntityManager() only if you truly need manual close semantics
Example fix
// before
try (StatelessSession s = injectedStatelessSession) { s.insert(o); } // close() throws
// after
@Transactional
public void add(Object o) { injectedStatelessSession.insert(o); } Defensive patterns
Strategy: type-guard
Validate before calling
// never call close() on injected sessions; guard by ownership check
if (session instanceof TransactionScopedStatelessSession) {
// managed by Quarkus: do NOT close
} Type guard
boolean isContainerManaged(StatelessSession s) {
return s instanceof TransactionScopedStatelessSession;
} Try / catch
try {
doWork(statelessSession);
} catch (IllegalStateException e) {
if (e.getMessage().contains("Not supported")) {
Log.warn("Attempted to close a container-managed session");
} else { throw e; }
} Prevention
- Never wrap injected sessions in try-with-resources
- Remove close()/finally cleanup copied from plain Hibernate code
- Let Quarkus manage session lifecycle; scope work with @Transactional
When it happens
Trigger: Explicitly calling statelessSession.close() (or Session.close() on a transaction-scoped session) in application code, e.g. in a finally block copied from plain-Hibernate code or try-with-resources on the injected session.
Common situations: Porting vanilla Hibernate code with try-with-resources around the session; defensive cleanup in finally blocks; wrapping the injected session in try-with-resources accidentally.
Related errors
- Persistence unit is closed
- Not supported for transaction scoped entity managers
- Methods that are annotated with JPA Listener annotations sho
- @PersistenceUnit annotations are not supported at the class
- This PersistenceProvider does not support createEntityManage
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/f295c1b26084db25.
Report an issue: GitHub.