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: NullPointerException at net.sf.hibernate.impl.SessionImpl
PostPosted: Fri May 21, 2004 2:29 am 
Newbie

Joined: Thu May 20, 2004 10:49 pm
Posts: 1
I am using Hibernate2.1.2 and jdk1.4
I encounter problem with lazy initialization when I do these:
(1)Load an object.
(2)Call getter or setter of that object. (If this step, everything is fine).
(3)Call Session.clear()
(4)Call a getter, which returns a Collection, of the object
(5)Get Iterator from the return Collection and at this point the following
exception occurs:
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:206)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java:130)
at test.Test.doSomeTest(Test.java:126)
at test.Test.main(Test.java:30)
Caused by: java.lang.NullPointerException
at net.sf.hibernate.impl.SessionImpl.initializeCollection(SessionImpl.java:3217)

This is the code:
net.sf.hibernate.Session sess = sessionFactory.openSession(connection);
MyClass myObj = (MyClass)sess.load(MyClassImpl.class, new Long(80224));
myObj.setDateTime(new java.util.Date());//if this is not here, no exception
System.out.println("clearing session.... ");
sess.clear();
System.out.println("cleared session.... ");
Collection theAttributes = myObj.getListOfAttributes();
Iterator iter = theAttributes.iterator(); //Exception occurs here
while(iter.hasNext()){
System.out.println(iter.next());
}

Anyone know of a solution to this problem ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 21, 2004 9:28 am 
Senior
Senior

Joined: Fri Nov 21, 2003 5:55 am
Posts: 155
Do you use a lazy= true? for your relationships?
You need to initialize them before access.
Read the documentation about lazy initialization in the chapter collection mapping.

good luck;)


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.