-->
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.  [ 7 posts ] 
Author Message
 Post subject: JSP and Lazy (Uninitialized) Collections
PostPosted: Tue Jan 10, 2006 5:13 pm 
[b]Hibernate version:3.05

Good day everybody!

I'm wondering how to use a tag logic:present or c:if test=${not empty} to verify if a lazyLoaded Collection is empty or not.

It always says that my lazyed Collection "is not present" even if try to use a scriptlet telling Hibernate to force initialization of my Collection:
org.hibernate.Hibernate.initialize( myForm.get("desiredProperty") );

Any ideas????


Cheers,


:Luiz.


Top
  
 
 Post subject: Before asking....
PostPosted: Tue Jan 10, 2006 5:16 pm 
Yes i do have a persistentCollection inside a form Object.

If i withdraw the tests (logic:present or c:if) the page loads without a problem.

The problem is when the Master Item has no childrem records.

Cheers,

:Luiz.


Top
  
 
 Post subject: Re: Before asking....
PostPosted: Tue Jan 10, 2006 5:34 pm 
Regular
Regular

Joined: Mon Nov 14, 2005 7:33 pm
Posts: 73
ldecaro wrote:
Yes i do have a persistentCollection inside a form Object.

If i withdraw the tests (logic:present or c:if) the page loads without a problem.

The problem is when the Master Item has no childrem records.

Cheers,

:Luiz.


One thing you might try is testing for an empty collection in your controller and initializing it w/ a blank Set, ArrayList, etc. before sending it to your view.

This would prevent an exception, if that's the problem you're having?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 5:34 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Presumably the session which loaded the uninflated objects has been closed by the time the JSP code gets its hands on those objects. So the lazily loaded objects are no longer available. This is correct. Your action classes should know which data your JSP pages are going to require, and inflate all of it (probably using Hibernate.initialize()).

It is unlikely that you should be looking at any lazily-loaded data from a JSP. You should ensure that all data required is loaded before closing your Hibernate session. Then you can use the normal isEmpty or forEach syntax, as appropriate.


Top
 Profile  
 
 Post subject: No, no it is opened...
PostPosted: Tue Jan 10, 2006 5:42 pm 
Dear tenwit i can assure you that my Session is still opened.

I have a filter that closes it. Besides if i do take off the testing the page loads succesfully.

What i do have implemented is a way to insert and delete Objects in graph from my JSP pages just by creating or deleting lines. That's why I have lazy Loaded Objects inside my JSP page.

But I haven't figured out yet is a way to test if my childrem records are "present" or not

Cheers,

:Luiz.


Top
  
 
 Post subject: Still can't figure.
PostPosted: Wed Jan 11, 2006 8:25 pm 
I've already tried to use some nested tags with no success.

Does Anybody have any ideas?

How do you guys check if a persistentSet is not empty && != null in jsp pages since all "normal" ways are not working???

Cheers,

:Luiz.


Top
  
 
 Post subject:
PostPosted: Thu Jan 12, 2006 12:15 am 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
Most of us follow hibernate's guidelines and use short-lived sessions. So not many people ever have to deal with this problem.


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