Hi,
Hibernate version: 3.2.5.ga
Mysql 5
I'm having some performance issues with hibernate. My project is based on appfuse-light with struts2-spring-hibernate. I have an import file called import.xml that among other things contains data of regions from which you can see below.
There are about 16000 of these elements. When starting the import it goes really fast. After a few seconds I have about 1000 of them stored in the database. But as the import goes on it gets slower and slower. In the end it only imports about 10 objects per second and in total it takes about 30 minutes to import all of these objects. I'm not sure why this is. Does anyone have any ideas? Below i provide some code snippets. If you need any more information just ask for it and I will try to provide it.
Any suggestions on how I can speed things up are most appreciated.
This is what the import data looks like:
Code:
<COUNTRIES>
<COUNTRY>
<CO_RECNO>6</CO_RECNO>
<CO_CODE>AD</CO_CODE>
<CO_DESC>ANDORRA</CO_DESC>
</COUNTRY>
.....
.....
.....
</COUNTRIES>
Iterating through all elements:Code:
List<Element> countryList = root.getChild("BASISDATA").getChild("GEOGRAPHY").getChild("COUNTRIES").getChildren();
for (Element country : countryList) {
regionService.updateRegionFromElement(country, Region.LEVEL_0);
}
Creating the region object and save it:Code:
public Region createRegion(String name, String smId, Region parent, String zipcode) {
Region region = regionManager.createRegion();
region.setName(name);
region.setSmId(smId);
if (parent != null) {
region.setParent(parent);
}
if (zipcode != null) {
region.setCode(zipcode);
}
region.setChildren(new HashSet<Region>());
region.setCompanies(new HashSet<Company>());
regionManager.saveRegion(region);
return region;
}
applicationContext-hibernate.xmlCode:
<property name="initialPoolSize"><value>10</value></property><property name="minPoolSize"><value>10</value></property>
<property name="maxPoolSize"><value>100</value></property>
<property name="maxStatements"><value>0</value></property>
<property name="properties">
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.cache.provider_class">org.hibernate.cache.OSCacheProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">true</prop>
</props>
</property>
Region.hbm.xml hibernate-mappingCode:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.medusa.model.Region" table="region" optimistic-lock="version">
<id name="id"
column="regionId"
type="java.lang.Long"
unsaved-value="null"
>
<generator class="native" />
</id>
<property name="version" />
<property name="smId" />
<property
name="name"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="name"
length="100"
not-null="false"
unique="false"
/>
<property
name="code"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="code"
length="30"
not-null="false"
unique="false"
/>
<many-to-one
name="parent"
class="org.medusa.model.Region"
cascade="none"
outer-join="auto"
column="parentId"
/>
<set
name="children"
table="region"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
order-by="name"
>
<cache usage="read-write" />
<key column="parentId" />
<one-to-many class="org.medusa.model.Region" />
</set>
<set
name="companies"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<cache usage="read-write" />
<key column="regionId" />
<one-to-many class="org.medusa.model.Company" />
</set>
</class>
</hibernate-mapping>