-->
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.  [ 6 posts ] 
Author Message
 Post subject: Help! Unknown Hibernate exception!!!!
PostPosted: Tue May 24, 2005 12:18 am 
Newbie

Joined: Tue May 24, 2005 12:11 am
Posts: 3
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

This is the error I encounter when try to initialize an object.

=======================================

80578 [24-05-2005 11:58:09] ERROR test.action.OutgoingAction - HibernateException
net.sf.hibernate.HibernateException: disconnected session
at net.sf.hibernate.collection.PersistentCollection.forceInitialization(PersistentCollection.java:339)
at net.sf.hibernate.Hibernate.initialize(Hibernate.java:255)
....

=======================================

This is part of the code I write...

public class OutgoingAction{
....
Hibernate.initialize(order.getOrderId());
List storeList = order.getOrderId().getList();
.....
}

Anyone see the above Hibernate exception before?

Thank you so much!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 24, 2005 10:50 am 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
see http://forum.hibernate.org/viewtopic.php?t=942798


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 4:34 am 
Newbie

Joined: Tue May 24, 2005 12:11 am
Posts: 3
Thanks for your reply zesj.
I have use session.isConnected to check and I am quite sure that the
session is still connected.

However, I find a strange things is that I use isInitialized() to check that object before Hibernate.Initialize...

{
...
System.out.println(Hibernate.isInitialized(order.getOrderId()));
Hibernate.Initialize(order.getOrderId());
....
}

Its printout is True!!!!

>_<


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 25, 2005 12:57 pm 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
try change
Code:
Hibernate.Initialize(order.getOrderId());

to
Code:
Hibernate.Initialize(order);

in documentation
http://www.hibernate.org/hib_docs/api/net/sf/hibernate/Hibernate.html#initialize(java.lang.Object)
initilize parameter is Object
Code:
initialize(Object proxy)
, not id.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 12:32 am 
Newbie

Joined: Tue May 24, 2005 12:11 am
Posts: 3
Thanks zesj! That function works now! ^_^

However, that session is still seems strange....the following are part of my code....

public class OutgoingAction{

....
printOrder(session,order);
session.save(order);
session.flush();
outputOrder(order, deliveryList, session);
session.save(deliveryList);
session.flush();
.....

public void printOrder(Session session, OutgoingOrder order){
Hibernate.initialize(order.getOrderId());
List storeList = order.getOrderId().getList();
....

}

public void outputOrder(OutgoingOrder order, List deliveryList, Session session){
List compareList = order.getOrderId().getList();
List tempList = deliveryList;
.....
}
.....
}

Now another exception happens:
===============================================
62266 [26-May-2005 12:18:49] ERROR net.sf.hibernate.LazyInitializationException - Failed to lazily initialize a collection - no session or session was closed
net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no session or session was closed
at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:214)
at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:71)
at net.sf.hibernate.collection.Set.iterator(Set.java:130)
===============================================

Is that again I have to do Hibernate.Initialize(order) in the function outputOrder?

Thank you so much!!!


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 26, 2005 9:15 am 
Regular
Regular

Joined: Tue May 24, 2005 10:19 am
Posts: 65
you can try:
1) if order.getOrderId() return ID(Long,integer, etc) , change to
Code:
Hibernate.Initialize(order)

2) if order.getOrderId() return Order object, continue with
Code:
Hibernate.Initialize(order.getOrderId())

3)try attach object in session before initialize
Code:
sess.lock(fritz, LockMode.NONE);

see: http://www.hibernate.org/hib_docs/reference/en/html_single/#manipulatingdata-update-lock


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