-->
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.  [ 1 post ] 
Author Message
 Post subject: could not initialize proxy - the owning Session was closed
PostPosted: Mon Oct 25, 2010 4:38 am 
Beginner
Beginner

Joined: Thu Nov 12, 2009 1:57 am
Posts: 22
I am trying to use hibernat template to execute the following code

Code:
HibernateFactory.buildSessionFactory();
sessionFactory = HibernateFactory.getSessionFactory();
template = new HibernateTemplate(sessionFactory);

template.saveOrUpdate(event);
Event obj = (Event) template.load(Event.class, event.getId());
assertEquals("Loads the event", event.getName(), obj.getName());


When the following line

Code:
obj.getName()


is executed I get the following error.

org.hibernate.LazyInitializationException: could not initialize proxy - the owning Session was closed


My config files are as follows:


Location.hbm.xml

Code:
<hibernate-mapping package="com.manning.hq.ch07">
    <class name="Location" table="locations">
        <id name="id" type="long" >
            <generator class="native"/>
        </id>
        <property name="name" type="string"/>
    </class>
</hibernate-mapping>


Event.hbm.xml

Code:
<hibernate-mapping package="com.manning.hq.ch07">
    <class name="Event" table="events">
        <id name="id" type="long" >
            <generator class="native"/>
        </id>
        <property name="name" type="string"/>
        <property name="startDate" column="start_date" type="date"/>
        <property name="duration" type="integer"/>
    </class>
</hibernate-mapping>


By any chance is the following line

Code:
template.saveOrUpdate(event);


closing the session. If you look at the config files, i have not defined any association, so lazy loading is not in picture. I am not able to understand why i get this error.
Can some help to understand the concept


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

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.