Home

setRollbackOnly

setRollbackOnly is a method in the Java Transaction API (JTA) used to mark the current global transaction for rollback. It is available on transactional control interfaces such as javax.transaction.UserTransaction and javax.transaction.Transaction. Calling this method signals the transaction manager that the transaction must not be committed, typically in response to an error condition or business rule violation detected during transactional work.

Once setRollbackOnly has been invoked, any subsequent attempt to commit the transaction will result in a rollback

setRollbackOnly does not immediately revert changes; it marks the transaction as rollback-only and defers the rollback

Usage context: Common in enterprise Java components that participate in global transactions, such as EJBs or

Notes: Availability and exact behavior may vary by transaction manager and container; attempting to call setRollbackOnly

See also: UserTransaction, Transaction, RollbackException, Status.

rather
than
a
commit.
The
actual
rollback
occurs
when
the
transaction
completes,
either
at
commit
time
when
the
manager
detects
the
flag
or
through
an
explicit
rollback.
If
a
caller
attempts
to
commit
after
marking
rollback-only,
a
RollbackException
(or
a
related
outcome)
may
be
thrown,
and
the
final
outcome
is
that
the
transaction
is
rolled
back.
to
commit
time.
It
can
still
be
used
to
perform
further
work
within
the
transaction
before
completion,
provided
the
transaction
manager
allows
it.
CDI
beans
using
JTA,
when
a
method
detects
a
condition
that
requires
aborting
without
propagating
an
error
to
the
caller
(which
may
be
handled
at
a
higher
level).
when
there
is
no
active
transaction
will
usually
throw
an
IllegalStateException.