Yo, guys, i found the problem!
So, I check "test" directory of Hibernate's sources.
There is FooBarTest.java that contains:
public void testPolymorphism() throws Exception {
Session s = openSession();
Bar bar = new Bar();
s.save(bar);
bar.setBarString("bar bar");
s.flush();
s.connection().commit();
s.close();
s = openSession();
FooProxy foo = (FooProxy) s.load( Foo.class, bar.getKey() );
assertTrue( "polymorphic", foo instanceof BarProxy );
assertTrue( "subclass property", ( (BarProxy) foo ).getBarString().equals( bar.getBarString() ) );
s.delete(foo);
s.flush();
s.connection().commit();
s.close();
}
I create the same test but I haven't used Proxy:
public void testGavPolymorphism() throws Exception {
Session s = openSession();
Bar bar = new Bar();
s.save(bar);
bar.setBarString("bar bar");
s.flush();
s.connection().commit();
s.close();
s = openSession();
Foo foo = (Foo) s.load( Foo.class, bar.getKey() );
assertTrue( "polymorphic", foo instanceof Bar );
assertTrue( "subclass property", ( (Bar) foo ).getBarString().equals( bar.getBarString() ) );
s.delete(foo);
s.flush();
s.connection().commit();
s.close();
}
testout
=======
testPolymorphism - Success
testGavPolymorphism - Error: java.lang.ClassCastException
Use the Source, Luke (C) Star Wars
;)
|