Hi,
I am new in Hibernate and I am using an application where I need to improve the performance while uploading the users through a utility. While analyzing the system, I found that, to insert a single user there were around 8 hits are made to DB to get the information and based on that finally it inserts the user and commits the transaction for each user. The strange thing I have noticed is that for every hit, a new DB connection is opened in code using the snippet getHibernateTemplate().getSessionFactory().openSession(); However, the connection is getting closed in finally block. But I think using this snippet only for every SQL query a new connection/disconnection is getting established.
I am not sure but I guess instead of using Open Connection; getCurrentSession can save this connection/disconnection every time and reuse the same connection and also speed up the entire process.
Can any one suggest whether I am on right track?
Also, when I have tried to use getCurrentSession I have simply replaced "getHibernateTemplate().getSessionFactory().openSession();" with "getHibernateTemplate().getSessionFactory().getCurrentSession();" from everywhere in code.
and in my applicationcontext.xml I have made following entries for Session Factory :
<bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" /> <property name="url" value="" /> <property name="username" value="" /> <property name="password" value="" /> </bean>
<bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean"> <property name="mappingResources"> <list> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernate.dialect">org.hibernate.dialect.OracleDialect</prop> <prop key="hibernate.show_sql">false</prop>
But when I tried to run the Utility I got some Hibernate Exception stating "No Hibernate Session bound to thread, and configuration does not allow creation". Could anyone suggest do I need to configure anything else in my applicationcontext.xml to use the getCurrentSession() method.
Can connection pooling helps in this issue because looking into applicationContext.xml I don't think connection pooling is used in this application at all.
Thanks in advance.
|