Well, with some help from my friends on here and after a lot of headaches, I have figured out how to make container-managed transactions (CMT) work on OC4J. Well, almost. When I intentionally throw bad data at my application, EJBException is thrown and all database changes are rolled back. That's the good news. That bad news is that when I try to throw good data at my application afterwards, I receive a DuplicateKeyException indicating that an entity with that primary key already exists.

Here is a simplified example of what I mean. A bad transaction is begun in a session bean method and propagates to an entity bean method that is supposed to insert a row in the database with primary key 4. The insert occurs, but later on in the transaction, EJBException is thrown. Thus the insert of record 4 is rolled back, and there is no longer a record 4 in the database. In the future, another transaction propagates to that entity bean to insert a record 4. This should be OK since there is such record in the database. However, the create method in the home interface throws the DuplicateKeyException as if there is some leftover EntityContext associated with an EJBObject from the first bad transaction.

I thought that the container, along with rolling back any database changes, destroys all bean instances associated with rolled back transactions. How can I ensure this happens? Thanks so much for your help.