[Logo] Terracotta Discussion Forums (LEGACY READ-ONLY ARCHIVE)
  [Search] Search   [Recent Topics] Recent Topics   [Members]  Member Listing   [Groups] Back to home page 
[Register] Register / 
[Login] Login 
[Expert]
LazyInitializationException with Web Sessions  XML
Forum Index -> Terracotta for Web Sessions
Author Message
albelsky

neo

Joined: 01/28/2013 20:09:46
Messages: 3
Offline

Hello Terracotta Gurus,

Our app stores detached Hibernate entities (some of them use lazy loading) as HTTP session attributes, and uses the OSIV (Open Session in View) pattern. When using Tomcat clustering, lazy loading works correctly with hydrated entities after session failover.

When I disable Tomcat clustering and try implementing Terracotta Web Sessions (open source version) following the Express installation guide, session replication seems to work, but lazy loading operations start throwing:
org.hibernate.LazyInitializationException: could not initialize proxy - no Session 

If I comment out the TerracottaTomcat70xSessionValve in Context.xml, and enable Tomcat clustering, everything works as expected again after a forced failover.

Does the Web Sessions product support this use case? Or would we have to use eager loading if we wanted to try Web Sessions?
I'm sorry, but I couldn't find the answers in the Terracotta documentation or on the web.

tc-config.xml:
Code:
<?xml version="1.0" encoding="UTF-8"?>
 <tc:tc-config xmlns:tc="http://www.terracotta.org/config"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://www.terracotta.org/schema/terracotta-6.xsd">
  <servers secure="false" xmlns:tc="http://www.terracotta.org/config" xmlns:con="http://www.terracotta.org/config" xmlns="">
   <server bind="0.0.0.0" host="127.0.0.1" name="node-1">
    <data>C:/libs/terracotta/server/node1/data</data>
    <logs>C:/libs/terracotta/server/node1/logs</logs>
    <statistics>C:/libs/terracotta/server/statistics</statistics>
    <dso-port bind="0.0.0.0">9510</dso-port>
    <jmx-port bind="0.0.0.0">9520</jmx-port>
    <l2-group-port bind="0.0.0.0">9530</l2-group-port>
    <data-backup>C:/libs/terracotta/server/node1/data-backup</data-backup>
    <index>C:/libs/terracotta/server/node1/index</index>
    <dso>
     <client-reconnect-window>120</client-reconnect-window>
     <persistence>
      <mode>permanent-store</mode>
     </persistence>
     <garbage-collection>
      <enabled>true</enabled>
      <verbose>false</verbose>
      <interval>3600</interval>
     </garbage-collection>
    </dso>
   </server>
   <server bind="0.0.0.0" host="127.0.0.1" name="node-2">
    <data>C:/libs/terracotta/server/node2/data</data>
    <logs>C:/libs/terracotta/server/node2/logs</logs>
    <statistics>C:/libs/terracotta/server/statistics</statistics>
    <dso-port bind="0.0.0.0">9511</dso-port>
    <jmx-port bind="0.0.0.0">9521</jmx-port>
    <l2-group-port bind="0.0.0.0">9531</l2-group-port>
    <data-backup>C:/libs/terracotta/server/node2/data-backup</data-backup>
    <index>C:/libs/terracotta/server/node2/index</index>
    <dso>
     <client-reconnect-window>120</client-reconnect-window>
     <persistence>
      <mode>permanent-store</mode>
     </persistence>
     <garbage-collection>
      <enabled>true</enabled>
      <verbose>false</verbose>
      <interval>3600</interval>
     </garbage-collection>
    </dso>
   </server>
   <mirror-groups>
    <mirror-group>
     <members>
      <member>node-1</member>
      <member>node-2</member>
     </members>
    </mirror-group>
   </mirror-groups>
   <ha>
    <mode>networked-active-passive</mode>
    <networked-active-passive>
     <election-time>5</election-time>
    </networked-active-passive>
   </ha>
  </servers>
  <system xmlns:tc="http://www.terracotta.org/config" xmlns:con="http://www.terracotta.org/config" xmlns="">
   <configuration-model>production</configuration-model>
  </system>
  
  <clients xmlns:tc="http://www.terracotta.org/config" xmlns:con="http://www.terracotta.org/config" xmlns="">
   <logs>C:/libs/terracotta/client/logs</logs>
  </clients>
   
 </tc:tc-config>

Environment:
Terracotta Server 3.7.3 (also tried 3.7.4) - ehCache 2.6.3, Web Sessions
Hibernate 3.2.7
Spring 2.5.5
Spring TC Server (Tomcat 7.0.25)

Thanks so much for your time.
klalithr

consul

Joined: 01/23/2011 10:58:07
Messages: 489
Offline

I dont consider myself a hibernate expert but I found that you get the
org.hibernate.LazyInitializationException when you access what hibernate considers as child elements outside of the hibernate transaction boundaries. One of the tricks I used (in an earlier job) was to simply cache the POJO itself (outside of detaching the hibernate object).
HTH!

Karthik Lalithraj (Terracotta)
albelsky

neo

Joined: 01/28/2013 20:09:46
Messages: 3
Offline

klalithr, thanks for responding. We'd like to keep the lazy loading approach, if possible. We have a complex and extensive domain object tree, so eager loading / preloading would mean a serious performance hit. Our codebase is quite large as well, so we'd like to keep the required amount of changes to the minimum.
We'll have to go with Tomcat clustering, as it works fine out of the box, and doesn't cause the LazyInitializationException issue...
 
Forum Index -> Terracotta for Web Sessions
Go to:   
Powered by JForum 2.1.7 © JForum Team