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?
|