• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

How to deal with List in jstl using forEach

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
how do I do my own kindle-like thing - without amazon
https://coderanch.com/t/711421/engineering/kindle-amazon
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!