I have an existing application with stateless session beans using CMT. Methods that don't require a transaction -- typically ones that are only reading from the database -- are marked as "Supports". Others that do updates to multiple tables that must operate atomically are marked as "Required".
I am attempting to convert our current persistence mechanism to Hibernate. I'm using the CMTTransactionFactory in JBoss along with SessionFactory.getCurrentSession as described here:
http://blog.hibernate.org/cgi-bin/blosxom.cgi/2005/04/12
I'm having a problem with the "Supports" methods. If they are not part of a larger transaction, then Hibernate throws a NullPointerException in getCurrentSession (the code appears to expect a transaction to always be available). If I label them all as "Required", then everything works.
What is the preferred way to handle this scenario? Is there a way to use a CMT method marked as "Supports" with Hibernate? Or is it safe/efficient to simply mark all the methods as "Required", even though there are times when the methods don't really need a transaction?