Code:
Code:
Query query = session.createQuery( "from person" );
Iterator results = query.iterate();
while ( results.hasNext() )
{
log.info( results.next() );
}
query = session.createQuery( "from person" );
List resultsList = query.list();
for ( Iterator iterator = resultsList.iterator(); iterator.hasNext(); )
{
log.info( iterator.next() );
}
Log:
Hibernate: select person0_.id as col_0_0_ from person person0_
Hibernate: select person0_.id as id0_, person0_.first_name as first_name0_0_, person0_.last_name as
last_name0_0_, person0_.age as age0_0_ from person person0_ where person0_.id=?
Hibernate: select person0_.id as id0_, person0_.first_name as first_name0_0_, person0_.last_name as
last_name0_0_, person0_.age as age0_0_ from person person0_ where person0_.id=?
(INFO ) SimpleCacheTest - MapMetaObject[ map={age=26, firstName=Matt, id=1, lastName=Veitas} ]
(INFO ) SimpleCacheTest - MapMetaObject[ map={age=33, firstName=Al, id=2, lastName=Veitas} ]
Hibernate: select person0_.id as id, person0_.first_name as first_name0_, person0_.last_name as last
_name0_, person0_.age as age0_ from person person0_
Exception being thrown:
Exception in thread "main" org.hibernate.WrongClassException: Object with id: 1 was not of the speci
fied subclass: person (loaded object was of wrong class)
at org.hibernate.loader.Loader.instanceAlreadyLoaded(Loader.java:663)
at org.hibernate.loader.Loader.getRow(Loader.java:612)
at org.hibernate.loader.Loader.getRowFromResultSet(Loader.java:248)
at org.hibernate.loader.Loader.doQuery(Loader.java:337)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:167)
at org.hibernate.loader.Loader.doList(Loader.java:1201)
at org.hibernate.loader.Loader.list(Loader.java:1186)
at org.hibernate.hql.QueryTranslatorImpl.list(QueryTranslatorImpl.java:872)
at org.hibernate.impl.SessionImpl.find(SessionImpl.java:812)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:84)
at com.osc.hibernate.cache.SimpleCacheTest.runTest(SimpleCacheTest.java:42)
at com.osc.hibernate.cache.SimpleCacheTest.main(SimpleCacheTest.java:59)[/b]