-->
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: Id choice and SELECT before INSERT performance
PostPosted: Fri Nov 30, 2007 7:32 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
Hi there.

I'm using hibernate; my classes all use a generated UUID type, so the Id is generated on the client (not the database).

I've got ClassA (many-to-one) ClassB.

When I do a session.save(classA), what I'm seeing is a SELECT for the Id of classB, which really slows things down with heavy imports. (and I do session.save(classB) later on anyway.

Tracing through the hibernate code, what it deos is in the DefaultSaveOrUpdateEventListener. It seems to want to work out if classB is transient or not (I'm not sure why - if it doesn't get saved, the database will roll back the transaction anyway). In the code, it does

ForeignKeys.isTransient( entityName, entity, getAssumedUnsaved(), source )

Which in turn asks various services if the reference is transient :
the interceptor (null : don't know)
the Entity Persister (the ID can't tell if it's unsaved or not as it's just an ID)
the 'assumed value' (set to null in AbstractEntityPersister)
then finally, it asks the database as all else has failed.

This seems a bit of a wasteful thing to do. I'd be perfectly happy if I did something stupid (like save A without saving B) that an integrity constraint would catch me. I could reverse the session.save order, but the real system is much more graphlike, so there's no 'ideal' ordering.

Is there a better way to do this? Could I just make an interceptor return 'FALSE' always? Is that safe?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 30, 2007 10:26 am 
Regular
Regular

Joined: Fri Feb 09, 2007 3:47 pm
Posts: 56
hmm - it seems all sorts of other bad things happen if I do that..

any other hints? This is operating on oracle - not sure if that makes a difference


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.