java - Connection pooling with hibernate 4 and struts2 -


After

I have a web application using struts2 implemeted and hibernate 4.3.5

I have encountered some problems and some clarification is required on some connection pooling properties.

I have used to create pooling connections with hibernate c3p0-0.9. 1.jar

Below are connection pooling properties in c3p0 in hibernate.cfg.xml

  & Lt ;! - Connection pooling c3p0 - & gt; & Lt; Property Name = "connection.provider_class" & gt; Org.hibernate.connection.C3P0ConnectionProvider & lt; / Property & gt; & Lt; Property Name = "hibernate.c3p0.min_size" & gt; 5 & ​​lt; / Property & gt; & Lt; Property Name = "hibernate.c3p0.max_size" & gt; 10 & lt; / Property & gt; & Lt; Property Name = "hibernate.c3p0.timeout" & gt; 500 & lt; / Property & gt; & Lt; Property Name = "hibernate.c3p0.max_statements" & gt; 2 & lt; / Property & gt; // I have heard somewhere that this property improves performance .. but do not know how it improves and & lt; Property Name = "hibernate.c3p0.idle_test_period" & gt; 300 & lt; / Property & gt; & Lt; Property Name = "hibernate.c3p0.preferredTestQuery" & gt; Choose sysdate from dual; & Lt; / Property & gt;   

In my application, I set the following property in the hibernte-cfg.xml

 
 * session- Per-request * pattern is used  & lt ;! - To open the connection when the request is hit - & gt; & Lt; Property Name = "hibernate.current_session_context_class" & gt; Thread & lt; / Property & gt;   

When I use this I am using session as the following

  // MyHiberantaeUtil here is your own class Having singleton patterns and creating static block // hibernet-cfg.xml and will create the SessionFactroy object. SessionFastria SessionFacture = MyHibernTutL.getSessionFactor (); Session session = sessionFactory.getCurrentSession ();   

According to the documentation .. When I use this pattern connection when request is requested and should be closed upon completion of the request. My case is its connection to the connection .. ie for the session I use this getCurrentSession () but it can not be closed when the request is finished.

`NumBusyConection = 2 (if it has two requests.)`

I would like to know that I do not remember anything. As expected, why the thread property is not working?

  And to say that the request is complete and has been generated from the request? Is the session-per-request best pattern or better for a pattern? I did not find this class `org.hibernate.connection.C3P0ConnectionProvider` in any jar file .. but my application is connecting to DB and working fine.   

Please thank you in advance

JDBC connection Then opened when necessary and closes for the first time. When you exit your service layer, you need to manually close the session:

  session.close ();   

Otherwise connections will not be closed and you will starve the connection pool.

This is a good idea to use the spring, because it is a support to automatically create. There is no match for offer for you / off session spring: < Ul>

  • Local transactions
  • Global transactions
  • Transaction annotations and automated comment runtime exceptions on success and rollback

    with hibernation Installing the Spring Hibernate Upalit Class is easy to use.

  • Comments

    Popular posts from this blog

    ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

    Matlab transpose a table vector -

    c# - Textbox not clickable but editable -