BMT beans use getStatus() instead of getRollbackOnly()

image with no caption

The getRollbackOnly() method returns a boolean—true if the method has been marked for rollback, false if nobody’s asked for a rollback. That’s all a CMT bean can (and needs) to know about the transaction’s status.

BMT beans, on the other hand, are more involved in controlling the transaction, and they might want to know a lot more. The getStatus() method in UserTransaction can tell you anything you’d ever want to know, and so much more, about how the transaction is doing.

Relax

You don’t need to memorize the status constants.

The getStatus() method returns an int representing a constant for things like: STATUS_ACTIVE, STATUS_COMMITTED, STATUS_COMMITTING, STATUS_THINKING_ABOUT_COMMITTING (just kidding on this one), STATUS_MARKED_ROLLBACK, STATUS_ROLLING_BACK, and our personal and most useful favorite, STATUS_UNKNOWN.

These constants are defined in the javax.transaction.Status interface (which has no methods, just a pile of these status constants), and you might find them helpful if you’re writing BMT code. But they’re not on the exam. You DO need to know that the getStatus() method is in UserTransaction, and that it’s the only way a BMT bean can find out if somebody called setRollbackOnly(), but that’s it.

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.