Announcement Announcement Module
Collapse
No announcement yet.
Integration with hibernate slowed the performance 7 times Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Integration with hibernate slowed the performance 7 times

    I started introduction of spring in existing project which already have hibernate for OR mapping. To have quick integration with spring i replaced HibernateUtil class (class responsible to provide thread safe session) with SessionFactoryUtils.getSession(sessionFactory, true);

    To my surprise performance went down by more then 7 times. On further investigation i found, new approach is creating new session on every request. Also i did not introduce Transaction management using spring. Am i doing something stupid?

    Here is my Datasource property


    <bean id="whseDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
    <property name="driverClassName" value="org.postgresql.Driver"/>
    <property name="url" value="jdbcostgresql://localhost:5432/dbname"/>
    <property name="maxActive" value="4"/>
    <property name="maxWait" value="1000"/>
    <property name="poolPreparedStatements" value="true"/>
    <property name="defaultTransactionIsolation" value="2"></property>
    <property name="maxIdle" value="1"></property>
    <property name="minIdle" value="0"></property>
    </bean>

    Here are hibernate properties

    <bean id="whseDBProperties" class="org.springframework.beans.factory.config.Pr opertiesFactoryBean">
    <property name="properties">
    <props>
    <prop key="hibernate.hbm2ddl.auto">update</prop>
    <prop key="hibernate.dialect">org.hibernate.dialect.Post greSQLDialect</prop>
    <prop key="hibernate.query.substitutions">true 'T', false 'F'</prop>
    <prop key="hibernate.show_sql">false</prop>
    <prop key="hibernate.current_session_context_class">thre ad</prop>
    </props>
    </property>
    </bean>

    Here is my session factory definition

    <bean id="whseSessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="dataSource">
    <ref local="whseDataSource"/>
    </property>
    <property name="exposeTransactionAwareSessionFactory"><value >false</value></property>
    <property name="hibernateProperties">
    <ref bean="whseDBProperties" />
    </property>
    <!-- OR mapping files. -->
    <property name="mappingResources">
    <list>
    <value>Tables</value>
    </list>
    </property>
    </bean>

  • #2
    Please use [ code][/code ] tags when posting code so that it remains readable !!! !!!

    You should also use transaction management, this is important to have proper resource management. Next to that your hibernate configuration is wrong, when using spring and not using JTA NEVER set the 'hibernate.current_session_context_class' as that breaks proper tx/resource management...

    Comment

    Working...
    X