• Post Reply Bookmark Topic Watch Topic
  • New Topic

session vs database persistence  RSS feed

 
gary stines
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,
I have a mvc jsp servlet application. There are several long running database transactions over multiple jsp pages. The question is, which is the best way(practice) to apply persistence?
either
1) save the database objects in the session and then apply them to the data base when the transaction is finished(using some object relational mapping technique)
or
2)set Connection.setAutoCommit(false) update, insert objects via sql to the database(again using some object relational mapping technique)and at the end of the transaction Connection.commit
Thanks, hope this is the right forum.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'd be saying either 'a', or a version of it. Keeping a database transaction open across multiple pages sounds dangerous.
You don't have to put the data on the session, you could also write it as hidden data to each page so that it all gets carried along.
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been asking myself the same question.
I initially chose to store form data from each form in one large session object thinking that it would be more effiecent than writing to a database to store data from each page.
Then the following article made me think that I did not make the right decision (see best practice #1).
http://www-3.ibm.com/software/webservers/appserv/ws_bestpractices.pdf
The article says that Session objects (at least in WAS) are serialized and stored in a database! It goes on to recommend that the developer explictly store form data into a database rather than keep large objects in session.
Another issue I came across is that my requirements changed. Initially my app had to take input from form 1, form 2 and form 3 and store the data in various tables in a database. Then the requirements changed to allow the user to enter multiple instances of form 2. So now my current design went from storing 3 forms worth of data in the session to storing possibly an infinite number of forms in the session (however unlikely).

A friend recently suggested a technique to help speed up the performance of storing large amounts of session data. Implement the readObject()/writeObject() methods (See Serializable API) to explicity write each data member of the session object to an ObjectInputStream/ObjectOutputStream. This eliminates the reflection overhead in the object Serialization process.
Regarding storing previous form data as hidden fields in the proceeding form, how would one handle multiple instances of a form (line items for example)?
-Graff
 
Roger Graff
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I found some additional advice for session managment using WAS 3.5. See chaper 7.
http://www.redbooks.ibm.com/pubs/pdfs/redbooks/sg246161.pdf
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!