-->
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: Usage assistance: JPA1 (hib 3.2), Bulk INSERT, MS SQL Server
PostPosted: Wed Jun 26, 2013 3:02 pm 
Regular
Regular

Joined: Fri Jul 30, 2004 4:02 pm
Posts: 50
Hey all,
I'm working on an old (jboss4) environment and trying to do some tuning while not upgrading the platform (changing what I can control).

One area is a BULK/BATCH INSERT section (>1000 inserts at once) on an MS SQL Server that has a lot of stored procedures.

Changes: I've setup the model to try to increase the BULK/BATCH INSERT (they are all insert, not updates) as follows (using 'InsertModel' for reference).

1) Change InsertModel ID generator to TABLE_GENERATOR to avoid relying on the MS SQL identity during a BULK INSERT of >1000 items
2) setup JDBC batch size (currently at 1000, not sure if that is too high or not).
3) Set flushmode to COMMIT instead of AUTO -- note, this is a JavaEE app not javaSE, so relying on the built-in transaction support.
4) modify the insert manager code to loop through 1000 at a time before doing em.flush()/em.clear() to the JDBC batch size

After making all those changes, 10,000 inserts went from 15 seconds down to 2.5 seconds...in a controlled environment where I removed the IDENTITY column of the table in question.

PROBLEM:
As I mentioned, the MS SQL server has a lot of stored procedures that also do inserts to the table beneath the 'InsertModel', and the sprocs are relying on the IDENTITY (Eventually these will all be changed, but too big to tackle right now). The above changes DO NOT WORK with the IDENTITY unless there is some way, in JavaEE, to set IDENTITY_INSERT to ON during the batch insert operations (or any operation with the model....). How can this be accomplished? (preferably with JPA-only, but if hibernate specific is there a way to still have it be managed by the transaction for rollback purposes)

Thanks for any input...refactoring old code to improve it without breaking it is always tough :-)

EDIT: Along these lines, is there a programmatic way to get the Dialect of the database connected to through JPA or Hibernate to help select the 'IDENTITY_INSERT' code only when MS SQL is detected? (currently it will always be MS SQL, but the long term is to migrate everything to be DB-agnostic but keep appropriate tuning coded behind this check).

-Darren


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.