This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi all, I have a question regarding transaction management in a JSP-Servlet-Javabean (MVC) arch. I have written a connection pool class and getting free connections from the pool wherever needed. I have some business objects like user, application etc(Object-Relational mapping). Those are not EJBs but I have written entire jdbc code in those business objects to handle create, update, remove or find operations. Now my problem is, I have to handle transaction within a client servlet which creates, updates and deletes some record from separate table thru those business objects, since the business objects use separate connection objects from pool I am not being able to handle the transaction using commit and rollback methods of connection. Does anybody have a soln. for this? Shubhashis
Hi... Actually You would need to change your architecture a bit...In case of Transaction don't return the connection back to pool, keep it in some hashtable [maintained by a singleton (i.e. single instance class) on server] keeping some ID (say ContextId) as key and connection as value. maintain this ContextId at client end...next time you need the connection to continue/commit/rollback the transaction, take it from the hashmap on the basis of Id your client prgm is passing. do watever you want to do with this connection and return it to the pool only when you are done. and yes don't forget to turn autocommit property false before you start using connection for a transaction. also keep contextid unique. hope this helps.
------------------ Amit Agrawal, New Delhi, India. [This message has been edited by A Agrawal (edited August 16, 2001).]