On Tuesday 12 February 2002 00:19, you wrote:
> I'm guessing, if you spotted this bug, you know how to write a test
> for it ... ?
I spotted it because I thought 6 seconds for retrieving a single object
from the database isn't what one can call good performance... (but I
think 6 seconds are very ok to load the whole database ;-). But you
can't test this, so my solution for an automated test looks like this:
protected void testLazyCollections(SessionFactory sessions) throws
Exception {
Session s = sessions.openSession();
Qux q = (Qux) s.create(Qux.class);
s.commit();
s = sessions.openSession();
q = (Qux) s.load( Qux.class, new Long( q.getKey() ) );
s.commit();
boolean ok = false;
try {
q.getMoreFums().isEmpty();
}
catch (RuntimeException e) {
ok = "Hibernate failed trying to load a
collection".equals(e.getMessage());
}
assert( ok, "lazy collection with one-to-many" );
ok = false;
try {
q.getFums().isEmpty();
}
catch (RuntimeException e) {
ok = "Hibernate failed trying to load a
collection".equals(e.getMessage());
}
assert( ok, "lazy collection with many-to-many" );
s = sessions.openSession();
q = (Qux) s.load( Qux.class, new Long( q.getKey() ) );
s.delete(q);
s.commit();
}
|