Interesting Java behavior
ListfooList = getFooFromHibernate();
for (Foo foo : fooList)
{
// do stuff
}
I was getting ClassCastExceptions while iterating through the list. It took a while to figure out, but the getFooFromHibernate method had a join to the BAR table in it without selecting the fields. Because of this Hibernate dumped a Foo into the list AND a Bar. When I iterated through the list, I got the exception.
This behavior can be caught with integration tests by iterating through the lists retrieved from the database.
2 Comments:
sounds like interesting Hibernate behaviour. Is it Java's fault?
Why doesn't it use generics?
The problem is that the generics are checked at compile time, not at run time. Since Hibernate is loading untyped objects into a list at run-time, there isn't the type safety that you would expect.
Post a Comment
<< Home