Link to home
Start Free TrialLog in
Avatar of phoenixsilver
phoenixsilver

asked on

How can I minimize number of trips to the Database using CMP?

if I call 5 different setters on a CMP 2.0 bean is that 5 round trips to the DB?  If so is there a way to batch the calls or get it so that it executes a single update rather than 5?  Or does the container (Jboss 4) manage this for me?  My Director who's a Softie and not familiar with J2EE was asking, because in a method call we called 5 setters for updating a users profile and he asked if it was 5 trips to the DB.  I couldn't give a concrete answer.  Any help of this would be great.
Avatar of aozarov
aozarov

Though the J2EE spec does prevent such behaiver it is very unlikely for the application server to do that.
Normally DB interaction happens at the begining of the transaction and at the end (if commit). (That is definetly true for JBoss, and W.L)
Other times where you will find the application server apply the changes to the DB is before running a finder.
SOLUTION
Avatar of Jim Cakalic
Jim Cakalic
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of phoenixsilver

ASKER

I've seen both the Value object and the REQUIRED directive for transactions.  We actually use a stateless session facade (which is what I called the client) that interacts with the CMP.  Let's say we have a simple POJO object called User, I have a session fascade that handles the modifications of users called UserFacade.  I also have a CMP called UserEJB.  Now I believe that we have Transactions on or they are on by default with JBOSS because I've seen roll backs expections and such being thrown when we experienced FK issues with the DB.  How we've done it so far is we take any modifications from the User profile and populate a User POJO, call the session facade in the Struts Action class and pass the User POJO to the saveUser method of the POJO, in this method we get an CMP by the primary key which is the username and basically set all CMP values with the User POJO values.  

My ultimate question here is that my manager who comes from the .net world and isn't really familar with CMP would argue that using a transaction maybe costly or unneccassary so I wanted to know if there was a way to do with without transactions or value objects.   In .net they would be also limited to two options either Value Objects or Transactions, but the transactions would have to be manually invoked.  I thought maybe some how invoke all updates to occur at once.  Looks like there really are only two options.  I thought maybe there was a way.  
Not sure if I was clear on this, if we don't have transactions on updates get executed on every set am I correct?  I do believe we have transactions set to REQUIRED.
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Right, if you don't have transaction in places each set will
cause an update (like setAutoCommit(true)). That is very bad
not only from performance reasons but more so from data integretiy reasons.