• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Spring in Action - Spring + JSF

 
Emmanuel Borges
Greenhorn
Posts: 12
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I'm developing a 'Decision Support System' using JSF, AJAX, Hibernate and MySQL.

In the beginning of the project, I was having some problems with Hibernate because of the 'LazyInitializationExceptions'.

I figured out how to solve the problems with the sessions, but I don't think I reached the best solution for them.

I would like to know if Spring could help me with these kind of problems...
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Emmanuel F. Borges wrote:Hello,

I'm developing a 'Decision Support System' using JSF, AJAX, Hibernate and MySQL.

In the beginning of the project, I was having some problems with Hibernate because of the 'LazyInitializationExceptions'.

I figured out how to solve the problems with the sessions, but I don't think I reached the best solution for them.

I would like to know if Spring could help me with these kind of problems...


No.

I could stop there. ;)

Anyway, Spring does have an interceptor to do the whole SessionInView pattern, but really the problem is how Hibernate is used. And a Hibernate issue. What I mean is that most people don't fully understand what Hibernate is doing and fetching strategies and use the SessionInView pattern to solve their LazyInitializationExceptions, except there is a way much better solution.

Fetching should always always be a use case decision. Meaning the Use Case dictates how much data you should have Hibernate get in your queries for just that use case. Making your use case get all the data it needs. Nothing more, nothing less. Nothing more means you aren't bringing over too much data that isn't even being used. Nothing less means that there are proxies and N+1 queries slowing your performance and most likely causing LazyInitializationExceptions.

What this means is that I might write the same basic query more than once because I have different use cases that need to run that query but need different amounts of data.

I am going to move this to the ORM forum.

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic