aspose file tools*
The moose likes Other Application Frameworks and the fly likes How to deal with List in jstl using forEach Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "How to deal with List in jstl using forEach" Watch "How to deal with List in jstl using forEach" New topic
Author

How to deal with List in jstl using forEach

soonphei tin
Greenhorn

Joined: May 01, 2009
Posts: 2
Dear all,
I have a Category and SubCategory classes. Obviously, they are one-to-many relationship between Category and SubCategory. Below is the code fragment: -




I have populated the data and if Category is set as CommandClass as below........


When I refer to SubCategory using jstl within JSP like below....


I get JasperException with the below message: -


Has anyone encounter this before? Please advice. Thank yo
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

This is caused because Hibernate, by default, lazily loads your model objects for performance reasons. However, it can only load data from the database into your model while a Hibernate session is active. Generally, in Spring, the Hibernate session is controlled by transaction boundaries. In this case you can't really extend the transaction boundary because you're first accessing the collection in a JSP. There are a couple of other things you can do to overcome this - you can turn off lazy loading for that collection in your hibernate configuration (in your .hbm or in annotations) by setting fetch=FetchType.EAGER, or you can create a OpenSessionInViewFilter to keep the Hibernate session open in your JSPs. Both of these approaches may cause issues down the road - by setting FetchType.EAGER, all subcategories for all categories are populated every time - but if there just aren't that many of them, this isn't a problem. By creating an OpenSessionInViewFilter you can now do database calls in your view layer, and you may inadvertently do something that is computationally expensive, and receive no warning - like the exception here.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to deal with List in jstl using forEach
 
Similar Threads
Error is Spring MVC - items should be Map, Array or a collection.
Error on View - MultiActionController + Spring:bine
MySQL
error compiling view with spring mvc project
pagination exception in spring