0 Replies Latest reply on Aug 11, 2010 6:46 AM by Krishna Chintu

    problem when using session-per -reqest in Hibernate

    Krishna Chintu Newbie
      I have an web application running under JBoss(4.0) server.
      i am using Hibernate to access database.
      @Deatails of MyAPP:
      To process a request, my application will go thorough above 50 DAO's.
      For each request there so many updates/Insetrs/delete/selects,
      and some of them are related to the results from the latter query results in the same request.
      So many requests will arrive at the same time.
      Same request may come from different locations at the same time.
      Those reqeusts  may update the same tables and  may select same data from tables.
      any request for my application will accesss the same data from tables.

      Average response time for each request 2 sec.

      After go through some tutorials, i found Session-per-Request pattern and think will be usefull in my case.
      I created a new session for each new request, and will close it after the request process completed.

      But i think i will got some problems in future !

      At particular time two processes(for Request_1 and Request_2) accessing the Table_1 and inserting new row.
      One of the column in the table is Auto increment column(id).
      After inserting the data to table , the resultant id will be used latter in the process.
      if i use different sessions per different requests,
      then i will get Duplicate Key problem !
      Am i correct ? 


      Based on the auto increment column id value the remaining process will be done.

      But i think i may not get correct id value ?

      I think some isolation / congruency problems will occur.
      Am i correct ? 

      what should I Do?
      How i use session per pattern for my large application.
      can you please explain me how to use the session-per request in my application!
      Is hibernate will take of them /Not ?
      if Hibernate will do it how to config them/write code.

      Thank You..