The first thing we did was mark our bean to hold states and have its transactions managed by the server. An example of this is shown here:
@Stateful
@TransactionManagement
public class UserBean {
...
}
What happens then? There's no method that deals with adding or removing stuff or do any transaction management. But they are still managed. See the following code:
Transaction started
1 added
Transaction will be commited
Transaction commited? true
So, you have all the transaction intelligence without writing a single line of transaction stuff.
It will transact even when the bean releases its resources:
Transaction started
User logout. Resources will be released.
UserBean will be destroyed
Transaction will be commited
Transaction commited? true