The EJB specification says that we cannot use Bean Managed Transaction in Entity Beans. Why?
It's all about atomic operations on your data. If an operation updates more than one entity then you want the whole thing to succeed or the whole thing to fail, nothing in between. If you put commits in the entity beans then it's very difficult to rollback if an error occurs at some point late in the operation.
Think of an account transfer which takes money from the first account and then pays it into a second account. If the paying in part fails how do you put the money back in the first account? What about if that then fails too?
- Use the javax.transaction package
- Use a session bean to represent usecases and specify how transactions should be managed as part of the session bean's deployment descriptor.
Any good EJB book will explain more about this.