Hibernate version: 3
Database: DB2 8.1
My app is not able to lookup an object by id. I am logging the sql and I am not seeing the select statement. I don't know why. I am using Spring/Hiberernate. I will post my code below with the mapping. I know my code is hitting the method where the find by id is happening by it returns empty
Mapping file
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<!--
Auto-generated mapping file from
the hibernate.org cfg2hbm engine
-->
<class name="edu.bju.aem.model.Server" table="SERVER" schema="AEM">
<id name="id" type="long">
<column name="ID" />
<generator class="edu.bju.aem.util.IDGenerator">
<param name="tableName">SERVER</param>
</generator>
</id>
<many-to-one name="os" class="edu.bju.aem.model.OS" fetch="select" unique="true">
<column name="OSID" />
</many-to-one>
<property name="name" type="string">
<column name="SNAME" length="25" not-null="true" />
</property>
<property name="description" type="string">
<column name="DESCRIPTION" length="32700" />
</property>
<property name="stringProduction" type="string">
<column name="PRODUCTION" not-null="true" length="1" />
</property>
</class>
</hibernate-mapping>
code that has teh look up method
Code:
public class ServerDAOHibernate extends AbstractHibernateSpringDAO implements ServerDAO {
public ArrayList findAll() {
return new ArrayList(super.findAll(Server.class));
}
public Server find(long id) {
Server server = (Server)super.find(Server.class, new Long(id));
return server;
}
}
Code:
public abstract class AbstractHibernateSpringDAO extends HibernateDaoSupport implements GenericDAO{
public AbstractHibernateSpringDAO(){}
public Object find(Class clazz, Long id){
return getHibernateTemplate().load(clazz, id);
}
I don't know if it will be helpful but here is the error I am getting but I do not get it when the lookup happens(doesn't really happen) but when I get to my view and it tries to access the object that was passed to it
[11/15/05 12:57:47:812 EST] 2b832b83 LazyInitializ E org.hibernate.LazyInitializationException could not initialize proxy - the owning Session was closed
[11/15/05 12:57:47:875 EST] 2b832b83 LazyInitializ E org.hibernate.LazyInitializationException TRAS0014I: The following exception was logged org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed
at java.lang.Throwable.<init>(Throwable.java)
at java.lang.Throwable.<init>(Throwable.java)
at org.hibernate.exception.NestableRuntimeException.<init>(NestableRuntimeException.java:100)
at org.hibernate.LazyInitializationException.<init>(LazyInitializationException.java:18)
at org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:53)
at org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:84)
at org.hibernate.proxy.CGLIBLazyInitializer.intercept(CGLIBLazyInitializer.java:134)
at edu.bju.aem.model.Server$$EnhancerByCGLIB$$199f70d8.getName(<generated>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:41)
at java.lang.reflect.Method.invoke(Method.java:386)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:657)
at org.springframework.beans.BeanWrapperImpl.getPropertyValue(BeanWrapperImpl.java:643)
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:140)
at org.springframework.web.servlet.tags.BindTag.doStartTagInternal(BindTag.java:115)
at org.springframework.web.servlet.tags.RequestContextAwareTag.doStartTag(RequestContextAwareTag.java:68)
at org.apache.jsp._editServer._jspService(editServer.jsp :6)
at com.ibm.ws.webcontainer.jsp.runtime.HttpJspBase.service(HttpJspBase.java:89)
.....