PDA

View Full Version : Speeding up Hibernate startup


dbenoff
Feb 11th, 2006, 02:56 PM
I am working on my first Spring/Hibernate prototype webapp and am experiencing long startup times.

My config file is pasted below. I am loading about 15 mapping files and startup takes about 60 seconds. If I leave mappingResources empty, startup takes only 10 seconds.

By comparison, if I use my own sessionFactory and hibernate.cfg.xml, to load the 15 mapping files, startup takes about 10 seconds.

So for some reason loading the mappings within Spring takes five times as long as it does outside of Spring.

Is there anything I can do to speed this up? For various reasons, I must completely reload the application periodically, so hot replace workarounds will not work for me.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
<bean id="dataSource" name="dataSource" class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" destroy-method="close">
<property name="url">
<value>jdbc:mysql://localhost/pos</value>
</property>
<property name="user">
<value>admin</value>
</property>
<property name="password">
<value>admin</value>
</property>
</bean>


<!-- Hibernate SessionFactory -->

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFac toryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>

<!-- Must references all OR mapping files. -->
<property name="mappingResources">
<list>
<value>com/hibernate/Customer.hbm.xml</value>
<value>com/hibernate/Invoice.hbm.xml</value>
<value>com/hibernate/Payment.hbm.xml</value>
<value>com/hibernate/User.hbm.xml</value>
<value>com/hibernate/Invoiceitem.hbm.xml</value>
<value>com/hibernate/Credit.hbm.xml</value>
<value>com/hibernate/Item.hbm.xml</value>
<value>com/hibernate/Ticket.hbm.xml</value>
<value>com/hibernate/Journal.hbm.xml</value>
<value>com/hibernate/Adjustment.hbm.xml</value>
<value>com/hibernate/Comment.hbm.xml</value>
<value>com/hibernate/Itemtype.hbm.xml</value>
<value>com/hibernate/Customergroup.hbm.xml</value>
<value>com/hibernate/Customerdiscount.hbm.xml</value>
<value>com/hibernate/Project.hbm.xml</value>
</list>
</property>

<!-- Set the type of database; changing this one property will port this to Oracle, MS SQL etc. -->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>

<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransa ctionManager">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>


<bean id="customerGroupDAOTarget" class="com.dao.CustomerGroupDAO">
<property name="sessionFactory">
<ref local="sessionFactory" />
</property>
</bean>


<bean id="customerGroupDAO" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="target">
<ref bean="customerGroupDAOTarget" />
</property>
<property name="proxyInterfaces">
<value>com.dao.ICustomerGroupDAO</value>
</property>
<property name="interceptorNames">
<list>
<value>hibernateInterceptor</value>
</list>
</property>
</bean>

<!-- ========================= WEB INTERCEPTORS DEFINITIONS ========================= -->

<bean id="hibernateInterceptor" class="org.springframework.orm.hibernate3.HibernateInterc eptor">
<property name="sessionFactory">
<ref bean="sessionFactory" />
</property>
</bean>

</beans>

Colin Yates
Feb 11th, 2006, 04:27 PM
You are using hibernate3; have you updated the DTD in the mapping file, or is it pointing at 2.0?

dbenoff
Feb 11th, 2006, 04:39 PM
Thank you Yatesco, I did have the wrong DTD declaration in my mapping files.

Updating the mapping files fixed the issue.

Thanks again for the help!

Colin Yates
Feb 12th, 2006, 10:56 AM
Have you read the hibernate 2-3 migration guide: http://www.hibernate.org/250.html

It contains quite a few little gems :)