• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to deal with List in jstl using forEach

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
reply
    Bookmark Topic Watch Topic
  • New Topic