Hibernate version: 3.2.5
Mapping documents:
Code:
<hibernate-mapping>
<class name="database.models.Category" table="CATEGORIES" lazy="true">
<id name="id" type="java.lang.Integer" column="id">
<generator class="assigned"/>
</id>
<property name="name" type="java.lang.String" column="name" length="256" not-null="true"/>
<property name="userDefined" type="java.lang.Boolean" column="userDefined"/>
<property name="active" type="java.lang.Boolean" column="active"/>
<set name="items" lazy="true" cascade="all" inverse="true">
<key column="category" not-null="true"/>
<one-to-many class="database.models.Item"/>
</set>
</class>
</hibernate-mapping>
Code:
<hibernate-mapping>
<class name="database.models.Item" table="ITEMS" lazy="true">
<id name="id" type="java.lang.Integer" column="id">
<generator class="assigned"/>
</id>
<property name="name" type="java.lang.String" not-null="true"/>
<property name="modified" type="timestamp"/>
<many-to-one name="category" column="category" class="database.models.Category" not-null="true"/>
</class>
</hibernate-mapping>
Name and version of the database you are using:Have tried the following databases:
Apache Derby 10.3.2.1
H2 1.0.65
HSQLDB 1.8.0.8
The generated SQL (show_sql=true):18-Jan-2008 18:25:57 STDOUT: Hibernate: insert into ITEMS (name, modified, category, id) values (?, ?, ?, ?)
18-Jan-2008 18:25:57 STDOUT: Hibernate: insert into ITEMS (name, modified, category, id) values (?, ?, ?, ?)
etc., etc.,...
snip...
Algorithm:Code:
1,000,000 XML ITEMS
Start Loop 1
Get 1,000 XML ITEMS
transaction = session.beginTransaction();
Start Loop 2
SAX Parse, creating ITEM objects
if ( loopCount % 500 == 0 ) { //500, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
End Loop 2
transaction.commit();
session.clear();
End Loop 1
Hi,
I'm new to Hibernate and I'm currently experiencing a problem doing mass batch inserts into the database.
My application needs to insert around 1,000,000 records at a time, however, at present when I get to around 330,000 inserts, the insert rates drops dramatically.
I'm using the batching / transaction method detailed within the Hibernation reference manual,
Chapter 13. Batch processing, but this is not helping :(
Also, I've tried the batching fix (incorporated from Hibernate 3.4)
Optimize Hibernate for the bulk insertion of related entities, but specifying the hibernate.order_inserts property has not helped either.
In previous work with PHP / MySQL I have performed mass inserts to the database by creating long SQL INSERT instructions, i.e.
INSERT INTO table (id, name) VALUES (1, 'name1'), (2, 'name2')... etc.
The multi-instruction SQL statement method above improves insert performance by an order of magnitude! Does anybody know of a way I can get Hibernate to batch the inserts into a single SQL statement as opposed to multiple statements, say 500 at a time, not the full 1,000,000! :) ?
Also, ahem..., another problem :)
After getting 300,000 of the records into the database I restart my application, in order to try to insert the records that have not yet completed, but I then get a 'java.lang.OutOfMemoryError: Java heap space'. I'm sure this is something to do with the recursive nature of hibernate (i.e. pulling in all the Item records when loading the Category class), but I'm not sure how to fix it.
Any help appreciated!
Many Thanks,
Mark