Hi There,
I had been suggested by few people to design a system in the following architecture
ControllerServlet --> SLSB[Delegator] -> BusinessBean/DAO
The transaction handling is done in the DAO and it is user transactions [setting auto commit to false]. Now what is the advantage of this solution. The SLSB is just a delegator of requests, infact it too is like a controller, it just redirects the call to the corresponding DAOs. The reason quoted was that this allows in better transaction handling.. since the txns are handled in the DAO, what has the EJB[SLSB] to do with this. Please set aside reasons like component model, remote access, with respect to data access and transactions etc., does this have any advantage over a servlet->javabean->DAO approach.
-
what is the adv of CS->SLSB->DAO (7 messages)
- Posted by: mohamed zafer
- Posted on: October 28 2003 00:54 EST
Threaded Messages (7)
- what is the adv of CS->SLSB->DAO by Tomas Inger on October 28 2003 02:46 EST
- what is the adv of CS->SLSB->DAO by Dinesh Sharma on October 28 2003 11:01 EST
- what is the adv of CS->SLSB->DAO by Gerald zhou on October 29 2003 08:09 EST
-
what is the adv of CS->SLSB->DAO by Dinesh Sharma on October 29 2003 08:36 EST
- what is the adv of CS->SLSB->DAO by Raj S on November 04 2003 09:39 EST
- Transaction does not rollback by mohamed zafer on February 21 2004 12:03 EST
-
what is the adv of CS->SLSB->DAO by Dinesh Sharma on October 29 2003 08:36 EST
- what is the adv of CS->SLSB->DAO by Gerald zhou on October 29 2003 08:09 EST
- DAO's by Sean Sullivan on October 28 2003 11:14 EST
-
what is the adv of CS->SLSB->DAO[ Go to top ]
- Posted by: Tomas Inger
- Posted on: October 28 2003 02:46 EST
- in response to mohamed zafer
Hi!
When you execute code (including your DAO) in the EJB container, you are not allowed to manage transactions. The EJB container does this job, and will normally not allow you to do it. (I know that OC4J from Oracle throws an exception when you make Connection.commit() in the EJB container.)
Chapter 17 in the EJB 2.1 spec. is about transactions. In section 17.3.4 it is said that you are not allowed to call commit() or rollback() if you let the container manage the transactions.
If you want to make commit and rollback explicitly on you JDBC connection you have to execute the code in the servlet container and use the Servlet->JavaBean->DAO approach you propose.
/Tomas -
what is the adv of CS->SLSB->DAO[ Go to top ]
- Posted by: Dinesh Sharma
- Posted on: October 28 2003 11:01 EST
- in response to mohamed zafer
This may not be in direct response to your question, but one thing I would recommend is that the transactions should be handled by your SLSB, and not your DAO. You can issue a rollback in your DAO (since the DAO is providing the persistence service and is responsible for maintaining the data integrity of its own data), but commits should always be issued by the use case controller (in your case the SLSB) requesting the persistence service. The reason being, the DAO could be called in many different contexts (by many different use case controllers), and it should be the caller who should make the final call on when the data/transaction should be committed, because it is the caller who started it, and knows best about the business functionality. (this is very important if you have one use case SLSB calling other use cases in order to perform a task)
Thanks
DS -
what is the adv of CS->SLSB->DAO[ Go to top ]
- Posted by: Gerald zhou
- Posted on: October 29 2003 08:09 EST
- in response to Dinesh Sharma
I have some problem about DAO.I use dao object insert some recorde,which time the connection.commit method will be invoked in EJB container. -
what is the adv of CS->SLSB->DAO[ Go to top ]
- Posted by: Dinesh Sharma
- Posted on: October 29 2003 08:36 EST
- in response to Gerald zhou
I have some problem about DAO.I use dao object insert some recorde,which time the connection.commit method will be invoked in EJB container.
Am assuming you are referring to Container Manager Transactions, and if so, the container would commit the transaction at the end of the EJB method call that initially invoked the transaction. So if your SLSB calls a DAO, and the DAO inserts a record, and passes the control back to the SLSB, at the time when SLSB method ends, the container will commit the transaction. Hope thats what you are looking for.
Thanks
DS -
what is the adv of CS->SLSB->DAO[ Go to top ]
- Posted by: Raj S
- Posted on: November 04 2003 09:39 EST
- in response to Dinesh Sharma
Hi there,
I generally prefer to do Controller -> SLSB -> DAO where the transactions are handled by SLSB. I havent come across any problem so far with this type of implementation. So I would prefer to have SLSB managing Transactions and DAOs doing Data Access....
GUYS... If you know any issues on using this strategy in implementation please do let me know...
Thanks and Regards
Raj -
Transaction does not rollback[ Go to top ]
- Posted by: mohamed zafer
- Posted on: February 21 2004 12:03 EST
- in response to Dinesh Sharma
I am using CMT in SLSB, from where I invoke a dao which inserts into two tables. The insert into the second table fails due to invalid data, but the transaction is not rolled back, there is a new record in the first table, which should not have been there in case of a successfull rollback. I have tried using setRollbackOnly(), but this too does'nt work. It is the same case if you use bean managed transactions too, the transaction is getting rollback even after calling the rollback() statement.
Any suggestions..
Mohamed Zafer -
DAO's[ Go to top ]
- Posted by: Sean Sullivan
- Posted on: October 28 2003 11:14 EST
- in response to mohamed zafer
My company builds simple web applications.
We have: a controller servlet, "service" objects, business (value) objects, and DAO's
If you want to learn more abut transaction demarcation and DAO's, please read my article:
http://www-106.ibm.com/developerworks/java/library/j-dao/