-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: find by id not working
PostPosted: Tue Nov 15, 2005 4:22 pm 
Beginner
Beginner

Joined: Sun Dec 05, 2004 10:25 am
Posts: 23
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)
.....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 4:40 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
the simple answer is change the top of your mapping file to this (I added the lazy line)

Code:
    <class name="edu.bju.aem.model.Server"
table="SERVER"
schema="AEM"
lazy="false"
>



if you want to know why, please do a search on the forums, there are a multitude of threads over this topic, or search the hibernate website for that exception :)

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 5:02 pm 
Beginner
Beginner

Joined: Sun Dec 05, 2004 10:25 am
Posts: 23
that worked great. I am not trying to be a pest but I did do a quck search and did 't find out why. Could you point me to a page with the reasoning as to why this didn't work for me?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 15, 2005 5:18 pm 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
http://www.hibernate.org/315.html
http://www.hibernate.org/43.html#A10
http://www.hibernate.org/hib_docs/api/n ... ption.html

http://forum.hibernate.org/credits.html

hope this helps

_________________
Chris

If you were at work doing this voluntarily, imagine what you'd want to see to answer a question.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.