Question

Domain Description

I am using a combination of
Spring + Hibernate + Tuckey Urlrewrite
In a Spring Framework Web app.

I have a simple data strucutre
Special has 1:Many Image object

I am using the language in the url:
http://site.com/en/someview or
http://site.com/de/someview and so on
There is also a default url:
http://site.com/

I am using Tucky Urlrewrite to rewrite the urls from
http://site.com/en/someview to
http://site.com/someview?lang=en
in order select the correct language for the page
(I am doing this to allow the user to simply change the language in the url and have the site change language accordingly)

I am loading the Special object in the Default controller
I am passing the Special object to the view and loading the Images there.

Problem Description

When hitting http://site.com/ everything works as expected. Looking at the logs for Turkey it is NOT doing any rewrite.

When hitting http://site.com/en/ or http://site.com/de/ i am getting the dreaded
"failed to lazily initialize a collection of role"

I can prove that there is something with Tuckey Urlrewrite because when i enter the "rewritten" urls into the address bar they work and even removing Tuckey Urlrewrite all together.

I have tried the following

  • Loading the Images in the controller - did not work
  • Using the OpenEntityManagerInViewInterceptor -- did not work
  • Using Tuckey's dispatcher REQUEST/FORWARD -- did not work
  • Using Tuckey's type="redirect" -- did work but as expected redirected the browser
  • Used the OneToMany attribute's fetch=FetchType.EAGER -- worked (but in the long term not desirable)

I am open to all suggestions to remove the use of the FetchType.EAGER.

Some ideas i have are
- Different method of Url rewriting i.e. if it is possiable to set tomcat to handle the rewrite before the DispachFilter - Different urlrewriter i.e. different product, or internal Spring URL Rewriter

Sites i have read

Really would be very thankful for any hints

Adam

Was it helpful?

Solution

If you use OpenSessionInViewFilter/OpenEntityManagerInViewFilter, make sure that one of the following is true:

  • <filter-mapping> of Open...InViewFilter is declared before <filter-mapping> of the Tuckey filter

  • <filter-mapping> of Open...InViewFilter contains <dispatcher>FORWARD</dispatcher>.

Otherwise your Open...InViewFilter won't be invoked, because Tuckey filter performs a forward when rewriting a URL, therefore filters declared after it should have <dispatcher>FORWARD</dispatcher> in order to be invoked.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top