JeanNiBee wrote:
WTH?
This works:
Wwritten directly in a .jsp just for edicational purposes and ease of implementation...
<%
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + " AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
%>
<display:table name="dogList">
<display:column property="id" title="ID" />
<display:column property="name" title="Name"/>
<display:column property="sex" title="Sex"/>
</display:table>
Name: <%= dog.getName() %> - <%= dog.getSex() %><BR>
<%
}
tx.commit();
HibernateUtil.closeSession();
%>
This does not and produces the error in the subject.
<%
ArrayList dogList = new ArrayList();
SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session hibSession = HibernateUtil.currentSession();
Transaction tx = hibSession.beginTransaction();
Query query = hibSession.createQuery( "FROM " + Dog.class.getName() + " AS c WHERE c.sex = :sex" );
query.setCharacter("sex", 'M');
Dog dog = new Dog();
for (Iterator it = query.iterate(); it.hasNext();) {
dog = (Dog) it.next();
dogList.add( dog );
}
tx.commit();
HibernateUtil.closeSession();
%>
<display:table name="dogList">
<display:column property="id" title="ID" />
<display:column property="name" title="Name"/>
<display:column property="sex" title="Sex"/>
</display:table>
What version of hibernate are you using ?
What do your mapping files look like ?
Exactly what exception are you receiving ? (Include the stack trace)
If you're using Hibernate 3.0.x, read the documentation. It covers this situation very explicitly when talking about Lazy Initialization.