These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Direct SQL INSERT and ID generation
PostPosted: Thu Feb 10, 2005 9:38 am 
Newbie

Joined: Thu Feb 10, 2005 8:42 am
Posts: 1
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.