-->
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.  [ 2 posts ] 
Author Message
 Post subject: [Foreign Key] "Extra" SQL Update statement
PostPosted: Wed Jan 09, 2008 11:46 am 
Newbie

Joined: Wed Jan 09, 2008 11:13 am
Posts: 4
Hi all,

I'm doing some performance tests on a Java program using Hibernate and when I had a closer look on what kind of queries are generated by hibernate I was a bit surprised.
I explained myself. Basically, my program manages tables linked with a simple foreign key and when I'm inserting records in those tables. hibernate is using one insert sql statement per table and one sql statement to update the foreign key to link the tables.
So, If I'm right, for two tables linked by a foreign key, there are three queries and I was wondering if it was possible to reduce to two.
Instead of doing an update of the foreign key column, will it be possible to do 2 inserts with the value of the foreign key?

If someone understood me ;) and have a clue to do it, please let me know

Thanks


Top
 Profile  
 
 Post subject: Additionnal information
PostPosted: Thu Jan 10, 2008 12:17 pm 
Newbie

Joined: Wed Jan 09, 2008 11:13 am
Posts: 4
Hi all,

Here are some additionnal information about this post. I've downloaded the hibernate sources and modified the org.hibernate.persister.collection.AbstractCollectionPersister class (method "public void recreate(PersistentCollection collection, Serializable id, SessionImplementor session) throws HibernateException" as followed

if ( isInsertCallable() ) {
CallableStatement callstatement = session.getBatcher()
.prepareBatchCallableStatement( getSQLInsertRowString() );
callstatement.registerOutParameter( offset++, Types.NUMERIC ); // TODO: should we require users to return number of update rows ?
st = callstatement;
// }
// else {
// st = session.getBatcher().prepareBatchStatement( getSQLInsertRowString() );


Therefore, there's no more update sql statement.

I know that it will break the links between tables but the purpose of this test is to see how much time is wasted on doing the update sql statement

Results:
I saved 30 seconds on a 2 minutes commit !!

Can this foreign key value be set in the Insert SQL Statement?? I think it would improve performances.

If someone can help me on this subject it would be great

Thx


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

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.