nickvajberg wrote:
I have a class A which relates to three other classes, B,C,D, using many-to-one. The relations are through property-ref.
When i call session.find("from A"), Hibernate does a select on B,C,D for _each_ instance of A.
Because of this, it takes ~20 seconds to query a few hundred objects. I coded this in JDBC and it took less than half a second, but then I was able to cache the B,C,D's manually.
The B,C,D classes are few and should be cached, but Hibernate doesn't do that. I've turned on caching, but nothing happends.
Any suggestions how to prevent the extra selects? Fetch depth doesn't help, perhaps because it's a property-ref ? ;-( Nor does Hibernate utilize the cache.
Use lazy="true" for your set's in the mapping file. This way when you load A you won't load B, C and D.