Question:
I need to batch insert/update ~20000 records in a PERSON table.
I've read the "Batch processing in Hibernate" paper and would like to use direct JDBC statements.
However, the PERSON table is also mapped to a Person class, which is used in the application to create new persons from a web front-end.
So my batch INSERT should use new IDs that don't conflict with the ones generated by the IdentifierGenerator used by Hibernate for the Person class.
How can I ensure that?
I thought about using the same IdentifierGenerator instance, but it seems that the only way to obtain a reference to the IdentifierGenerator used for a class is to use implementor interfaces:
Code:
ClassPersister classPersister = ((SessionFactoryImplementor) sessionFactory).getPersister(Person.class);
Person person = new Person();
IdentifierGenerator idGenerator = classPersister.getIdentifierGenerator();
Serializable id = idGenerator.generate((SessionImplementor) session, person);
Is this the right way to go or am I missing something?
Should I try to do the batch processing with Hibernate, instead?
Someone must have already had this kind of problem, but I couldn't find anything in the forum or the FAQ.
Hibernate version:
2.1.7C
Mapping documents:
<hibernate-mapping default-cascade="none">
<class name="mypackage.Person" table="PERSON">
<id name="id" type="java.lang.Long" column="ID" unsaved-value="null">
<generator class="seqhilo">
<param name="sequence">hi_value</param>
<param name="max_lo">100</param>
</generator>
</id>
<property name="serial" type="java.lang.String">
<column name="SERIAL" not-null="true" unique="true" sql-type="VARCHAR(256)"/>
</property>
<property name="name" type="java.lang.String">
<column name="NAME" not-null="true" unique="false" sql-type="VARCHAR(256)"/>
</property>
...
</hibernate-mapping>
Thank you.