-->
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.  [ 2 posts ] 
Author Message
 Post subject: Lazy Initialization Problem with Hibernate PersistentSet
PostPosted: Fri Jun 13, 2008 8:28 pm 
Newbie

Joined: Thu May 08, 2008 2:16 pm
Posts: 3
The following is my code:
Code:

    @SuppressWarnings("unchecked")
    public static void main(String[] args) {
        HibernateUtil.getSession();

        List b = new ArrayList();       
        b.add("1");
        b.add("2");
       
        List a = new org.hibernate.collection.PersistentList();
        a.addAll(b);
    }



And I got the following exception:
Code:
17:25:01,628  INFO SettingsFactory:294 - Deleted entity synthetic identifier rollback: disabled
17:25:01,628  INFO SettingsFactory:309 - Default entity-mode: pojo
17:25:01,628  INFO SettingsFactory:313 - Named query checking : enabled
17:25:01,691  INFO SessionFactoryImpl:161 - building session factory
17:25:02,644  INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
17:25:02,816 ERROR LazyInitializationException:19 - failed to lazily initialize a collection, no session or session was closed
org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:183)
   at org.hibernate.collection.PersistentList.addAll(PersistentList.java:189)
   at com.rim.mvs.configio.exception.Test.main(Test.java:35)
Exception in thread "main" org.hibernate.LazyInitializationException: failed to lazily initialize a collection, no session or session was closed
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationException(AbstractPersistentCollection.java:358)
   at org.hibernate.collection.AbstractPersistentCollection.throwLazyInitializationExceptionIfNotConnected(AbstractPersistentCollection.java:350)
   at org.hibernate.collection.AbstractPersistentCollection.initialize(AbstractPersistentCollection.java:343)
   at org.hibernate.collection.AbstractPersistentCollection.write(AbstractPersistentCollection.java:183)
   at org.hibernate.collection.PersistentList.addAll(PersistentList.java:189)
   at com.rim.mvs.configio.exception.Test.main(Test.java:35)



Does anyone can point out what the problem is? Thanks.

Allen

_________________
Yijia (Allen) Zhao

Research In Motion
Software Developer


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 14, 2008 12:42 am 
Regular
Regular

Joined: Sun Apr 13, 2008 3:04 am
Posts: 71
Location: Bangalore
Hi,

Do not create and use PersistentList.. PersistantList impl of hibernate is used for fetching and storing records to and from associated database. Hence when u add a object to the list, it looks for session to know sync up etc.

Regards,
Nagendra

_________________
Raja Nagendra Kumar,
C.T.O
http://www.tejasoft.com
TejaSoft - Specialists in Code Audit, Unit Testing and Merciless Re-factoring - Engineering Crisis Turnaround Experts


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.