I am wondering if it is possible to retrieve a CMT transaction controlled by the container? Say, I have a SessionBean that has "RequiresNew" as the CMT Tx attribute. In my code I would like to get a hold on this transaction - how is this possible?
Originally posted by David Follow: [QB]Say, I have a SessionBean that has "RequiresNew" as the CMT Tx attribute. In my code I would like to get a hold on this transaction
Why? The EJBContext gives you the getRollbackOnly() and setRollbackOnly() methods; what else could you possibly want to do that would not step on the containers toes?
CMT - Container Managed Transaction; i.e. Container: Hands off Bean this is my territory - you just tell me whether or not you can finish your job!
BMT - Bean Managed Transaction; i.e. Container: Fine, fine, micro-manage everything yourself why don't you - I'll even tell my guys to co-operate with you if they can - but don't expect any co-operation from the other square heads like you. (BMT transactions can propagate into a CMT bean (Mandatory,Required,Supported) but not into another BMT bean (no transaction can)).
posted 14 years ago
I am thinkign about something like Hibernate (or equivelent) that needs (or creates) it's own Tx, but I want Hinbernate to use the Tx of the container. I know that Hibernate has a Factory to retrieve the Tx of the AppServer, so I was just curious how they do it.
posted 14 years ago
Hibernate seems to get around that by "handling JTA transparently" (Hibernate in Action). Usually you leave the JTA details to your framework (Spring/Hibernate).
Just do it. CMT means neither Hibernate nor user code needs to worry about starting / stopping transactions. You should remember to set hibernate.transaction.manager_lookup_class for your application server.
In a CMT environment, it makes a great deal of sense to use SessionFactory.getCurrentSession(), and leave session management to Hibernate.