You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by John Studarus <st...@jhlconsulting.com> on 2004/01/06 19:29:22 UTC

hibernate/tapestry & lazy initalization

  I've been using Tapestry with Hibernate (and Tomcat 5)
for a few months now with great results.  I recently ran
into a problem that I am curious if anyone else has
encountered.
  I've been rely upon Hibernate to populate objects
for me from the database via OGNL calls in Tapestry.
However, at times, Tapestry calls Hibernate objects
(like the source in a foreach) without hitting any of
my code.  This means I don't have the opportunity to
create a Session for Hibernate to use and I end up
with an exception.
  I need to be able to create a session object
before Tapestry makes any calls into my Hibernate
objects.  Any ideas on how this could be done?  I've
created the Hibernate sessions in both the Tapestry
page constructor and inside the initialize call.  I
get the exception when Tapestry pulls up the Hibernate
object.  Or I wonder if Tapestry is doing its work
in a different thread than my code and can't see
my Thread specific session.
  This only effects Tapestry/Hibernate when lazy initalization
is turned on.  I have a feeling that most people use
lazy initalization when using Tapestry and Hibernate together
but the performance hit is too great for me to leave lazy
initalization turned on (difference between something taking
1.5 hours or 30 seconds...).
  There was a post out there about using a Filter - anyone
every tried that?  Any Hibernate/Tapestry experts out there?
  Thanks,

        John

net.sf.hibernate.LazyInitializationException: Failed to lazily initialize a collection - no Session
        at net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollection.java:167)
        at net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.java:64)
        at net.sf.hibernate.collection.Set.size(Set.java:114)
        at org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:568)
        at org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
        at org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
        at org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
...  cut ...


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: hibernate/tapestry & lazy initalization

Posted by John Studarus <st...@jhlconsulting.com>.
  That sounds slick - easier then creating a view.
What methods of the Engine class did you override?
Do you create a new session with each page view or
just one per Engine?

        John


On Wed, Jan 07, 2004 at 05:47:31PM +1100, Glen Stampoultzis wrote:
> 
> What I've done is create my own engine.  This handles creation and closing 
> of the session after the request is complete.  It automatically detects if 
> an exception has been thrown and will close the session and rollback any 
> active transactions.
> 
> Regards,
> 
> Glen
> 
> 
> At 09:43 AM 7/01/2004, you wrote:
> >I actually wrote the document mentioned, which  is available at:
> > http://www.springframework.org/docs/integration/tapestry.html
> >
> >As of the current 1.0M4 release, Spring actually offers built-in support 
> >for the Open Session in View 'pattern' with Hibernate.
> >
> >However, I am personally not a big fan of using that pattern, with or 
> >without Spring. The problem is due to the fact that as per the Hibernate 
> >docs, once a Hibernate Session throws an Exception, the Session is 
> >considered to be inconsistent, and should not be used any longer. If you 
> >use the Open Session in View pattern however, the Session is handled by a 
> >layer above your view code (the servlet filter or view interceptor in the 
> >Spring case), but your view code is calling down to other code (service 
> >layer) which may do something to kill the Session in this fashion without 
> >any of the layers above (the view layer or the layer actually handling the 
> >session) knowing anything about that, and the session may thus continue to 
> >be used by other view code.
> >
> >Personally, I think the best way to handle all of this is to create use 
> >case driven service layer code, which properly operates in a transaction 
> >(and handles the Hibernate session automatically via Spring), which 
> >returns all the needed data. With regards to lazy loaded data, it should 
> >touch any such data as needed for the use case.    Much less potential for 
> >getting into trouble.
> >
> >
> >John Meredith wrote:
> >
> >>Hi John,
> >>
> >>Somehow I missed the original post (no idea where my filters have
> >>filtered it off to) ...
> >>
> >>Anyway, what I find works very well is the "Open Session in View"
> >>pattern/filter: http://www.hibernate.org/43.html
> >>
> >>A session is opened for the entire request and automatically closed.
> >>
> >>Another thing worth looking into is possibly the Spring Framework. I've
> >>played around with it briefly ... from memory, there's also a tutorial
> >>available for using Tapestry + Spring + Hibernate on their Wiki.
> >>
> >>Hope this helps.
> >>
> >> - John
> >>
> >>On Tue, 2004-01-06 at 20:19, Eric Schneider wrote:
> >>
> >>
> >>>John,
> >>>
> >>>Try creating the session in prepareForRender(), see if that makes a
> >>>difference.
> >>>
> >>>Cheers,
> >>>Eric
> >>>
> >>>----- Original Message ----- From: "Jamie Orchard-Hays" <ja...@dang.com>
> >>>To: "Tapestry users" <ta...@jakarta.apache.org>;
> >>><st...@jhlconsulting.com>
> >>>Sent: Tuesday, January 06, 2004 2:11 PM
> >>>Subject: Re: hibernate/tapestry & lazy initalization
> >>>
> >>>
> >>>
> >>>
> >>>>I don't think initialize() is where you want to do this. That's where 
> >>>>you
> >>>>set properties to the default values you want when you are *finished* 
> >>>>with
> >>>>the page (usually null).
> >>>>
> >>>>
> >>>>----- Original Message ----- From: "John Studarus" 
> >>>><st...@jhlconsulting.com>
> >>>>To: <ta...@jakarta.apache.org>
> >>>>Sent: Tuesday, January 06, 2004 1:29 PM
> >>>>Subject: hibernate/tapestry & lazy initalization
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>> I've been using Tapestry with Hibernate (and Tomcat 5)
> >>>>>for a few months now with great results.  I recently ran
> >>>>>into a problem that I am curious if anyone else has
> >>>>>encountered.
> >>>>> I've been rely upon Hibernate to populate objects
> >>>>>for me from the database via OGNL calls in Tapestry.
> >>>>>However, at times, Tapestry calls Hibernate objects
> >>>>>(like the source in a foreach) without hitting any of
> >>>>>my code.  This means I don't have the opportunity to
> >>>>>create a Session for Hibernate to use and I end up
> >>>>>with an exception.
> >>>>> I need to be able to create a session object
> >>>>>before Tapestry makes any calls into my Hibernate
> >>>>>objects.  Any ideas on how this could be done?  I've
> >>>>>created the Hibernate sessions in both the Tapestry
> >>>>>page constructor and inside the initialize call.  I
> >>>>>get the exception when Tapestry pulls up the Hibernate
> >>>>>object.  Or I wonder if Tapestry is doing its work
> >>>>>in a different thread than my code and can't see
> >>>>>my Thread specific session.
> >>>>> This only effects Tapestry/Hibernate when lazy initalization
> >>>>>is turned on.  I have a feeling that most people use
> >>>>>lazy initalization when using Tapestry and Hibernate together
> >>>>>but the performance hit is too great for me to leave lazy
> >>>>>initalization turned on (difference between something taking
> >>>>>1.5 hours or 30 seconds...).
> >>>>> There was a post out there about using a Filter - anyone
> >>>>>every tried that?  Any Hibernate/Tapestry experts out there?
> >>>>> Thanks,
> >>>>>
> >>>>>       John
> >>>>>
> >>>>>net.sf.hibernate.LazyInitializationException: Failed to lazily
> >>>>>
> >>>initialize
> >>>
> >>>
> >>>>a collection - no Session
> >>>>
> >>>>
> >>>>>       at
> >>>>>
> >>>net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollec
> >>>
> >>>
> >>>>tion.java:167)
> >>>>
> >>>>
> >>>>>       at
> >>>>>
> >>>net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.j
> >>>
> >>>
> >>>>ava:64)
> >>>>
> >>>>
> >>>>>       at net.sf.hibernate.collection.Set.size(Set.java:114)
> >>>>>       at
> >>>>>
> >>>org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:
> >>>
> >>>
> >>>>568)
> >>>>
> >>>>
> >>>>>       at
> >>>>>
> >>>>org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
> >>>>
> >>>>
> >>>>>       at
> >>>>>
> >>>>org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
> >>>>
> >>>>
> >>>>>       at
> >>>>>
> >>>>org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
> >>>>
> >>>>
> >>>>>...  cut ...
> >>>>>
> >>>>>
> >>>>>---------------------------------------------------------------------
> >>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >>>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >>>>>
> >
> >
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> 
> 
> Glen Stampoultzis
> gstamp@iinet.net.au
> http://members.iinet.net.au/~gstamp/glen/

---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: hibernate/tapestry & lazy initalization

Posted by Glen Stampoultzis <gs...@iinet.net.au>.
What I've done is create my own engine.  This handles creation and closing 
of the session after the request is complete.  It automatically detects if 
an exception has been thrown and will close the session and rollback any 
active transactions.

Regards,

Glen


At 09:43 AM 7/01/2004, you wrote:
>I actually wrote the document mentioned, which  is available at:
>  http://www.springframework.org/docs/integration/tapestry.html
>
>As of the current 1.0M4 release, Spring actually offers built-in support 
>for the Open Session in View 'pattern' with Hibernate.
>
>However, I am personally not a big fan of using that pattern, with or 
>without Spring. The problem is due to the fact that as per the Hibernate 
>docs, once a Hibernate Session throws an Exception, the Session is 
>considered to be inconsistent, and should not be used any longer. If you 
>use the Open Session in View pattern however, the Session is handled by a 
>layer above your view code (the servlet filter or view interceptor in the 
>Spring case), but your view code is calling down to other code (service 
>layer) which may do something to kill the Session in this fashion without 
>any of the layers above (the view layer or the layer actually handling the 
>session) knowing anything about that, and the session may thus continue to 
>be used by other view code.
>
>Personally, I think the best way to handle all of this is to create use 
>case driven service layer code, which properly operates in a transaction 
>(and handles the Hibernate session automatically via Spring), which 
>returns all the needed data. With regards to lazy loaded data, it should 
>touch any such data as needed for the use case.    Much less potential for 
>getting into trouble.
>
>
>John Meredith wrote:
>
>>Hi John,
>>
>>Somehow I missed the original post (no idea where my filters have
>>filtered it off to) ...
>>
>>Anyway, what I find works very well is the "Open Session in View"
>>pattern/filter: http://www.hibernate.org/43.html
>>
>>A session is opened for the entire request and automatically closed.
>>
>>Another thing worth looking into is possibly the Spring Framework. I've
>>played around with it briefly ... from memory, there's also a tutorial
>>available for using Tapestry + Spring + Hibernate on their Wiki.
>>
>>Hope this helps.
>>
>>  - John
>>
>>On Tue, 2004-01-06 at 20:19, Eric Schneider wrote:
>>
>>
>>>John,
>>>
>>>Try creating the session in prepareForRender(), see if that makes a
>>>difference.
>>>
>>>Cheers,
>>>Eric
>>>
>>>----- Original Message ----- From: "Jamie Orchard-Hays" <ja...@dang.com>
>>>To: "Tapestry users" <ta...@jakarta.apache.org>;
>>><st...@jhlconsulting.com>
>>>Sent: Tuesday, January 06, 2004 2:11 PM
>>>Subject: Re: hibernate/tapestry & lazy initalization
>>>
>>>
>>>
>>>
>>>>I don't think initialize() is where you want to do this. That's where you
>>>>set properties to the default values you want when you are *finished* with
>>>>the page (usually null).
>>>>
>>>>
>>>>----- Original Message ----- From: "John Studarus" 
>>>><st...@jhlconsulting.com>
>>>>To: <ta...@jakarta.apache.org>
>>>>Sent: Tuesday, January 06, 2004 1:29 PM
>>>>Subject: hibernate/tapestry & lazy initalization
>>>>
>>>>
>>>>
>>>>
>>>>>  I've been using Tapestry with Hibernate (and Tomcat 5)
>>>>>for a few months now with great results.  I recently ran
>>>>>into a problem that I am curious if anyone else has
>>>>>encountered.
>>>>>  I've been rely upon Hibernate to populate objects
>>>>>for me from the database via OGNL calls in Tapestry.
>>>>>However, at times, Tapestry calls Hibernate objects
>>>>>(like the source in a foreach) without hitting any of
>>>>>my code.  This means I don't have the opportunity to
>>>>>create a Session for Hibernate to use and I end up
>>>>>with an exception.
>>>>>  I need to be able to create a session object
>>>>>before Tapestry makes any calls into my Hibernate
>>>>>objects.  Any ideas on how this could be done?  I've
>>>>>created the Hibernate sessions in both the Tapestry
>>>>>page constructor and inside the initialize call.  I
>>>>>get the exception when Tapestry pulls up the Hibernate
>>>>>object.  Or I wonder if Tapestry is doing its work
>>>>>in a different thread than my code and can't see
>>>>>my Thread specific session.
>>>>>  This only effects Tapestry/Hibernate when lazy initalization
>>>>>is turned on.  I have a feeling that most people use
>>>>>lazy initalization when using Tapestry and Hibernate together
>>>>>but the performance hit is too great for me to leave lazy
>>>>>initalization turned on (difference between something taking
>>>>>1.5 hours or 30 seconds...).
>>>>>  There was a post out there about using a Filter - anyone
>>>>>every tried that?  Any Hibernate/Tapestry experts out there?
>>>>>  Thanks,
>>>>>
>>>>>        John
>>>>>
>>>>>net.sf.hibernate.LazyInitializationException: Failed to lazily
>>>>>
>>>initialize
>>>
>>>
>>>>a collection - no Session
>>>>
>>>>
>>>>>        at
>>>>>
>>>net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollec
>>>
>>>
>>>>tion.java:167)
>>>>
>>>>
>>>>>        at
>>>>>
>>>net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.j
>>>
>>>
>>>>ava:64)
>>>>
>>>>
>>>>>        at net.sf.hibernate.collection.Set.size(Set.java:114)
>>>>>        at
>>>>>
>>>org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:
>>>
>>>
>>>>568)
>>>>
>>>>
>>>>>        at
>>>>>
>>>>org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
>>>>
>>>>
>>>>>        at
>>>>>
>>>>org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
>>>>
>>>>
>>>>>        at
>>>>>
>>>>org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
>>>>
>>>>
>>>>>...  cut ...
>>>>>
>>>>>
>>>>>---------------------------------------------------------------------
>>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>>>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>


Glen Stampoultzis
gstamp@iinet.net.au
http://members.iinet.net.au/~gstamp/glen/

Re: hibernate/tapestry & lazy initalization

Posted by Colin Sampaleanu <co...@exis.com>.
I actually wrote the document mentioned, which  is available at:
  http://www.springframework.org/docs/integration/tapestry.html

As of the current 1.0M4 release, Spring actually offers built-in support 
for the Open Session in View 'pattern' with Hibernate.

However, I am personally not a big fan of using that pattern, with or 
without Spring. The problem is due to the fact that as per the Hibernate 
docs, once a Hibernate Session throws an Exception, the Session is 
considered to be inconsistent, and should not be used any longer. If you 
use the Open Session in View pattern however, the Session is handled by 
a layer above your view code (the servlet filter or view interceptor in 
the Spring case), but your view code is calling down to other code 
(service layer) which may do something to kill the Session in this 
fashion without any of the layers above (the view layer or the layer 
actually handling the session) knowing anything about that, and the 
session may thus continue to be used by other view code.

Personally, I think the best way to handle all of this is to create use 
case driven service layer code, which properly operates in a transaction 
(and handles the Hibernate session automatically via Spring), which 
returns all the needed data. With regards to lazy loaded data, it should 
touch any such data as needed for the use case.    Much less potential 
for getting into trouble.


John Meredith wrote:

>Hi John,
>
>Somehow I missed the original post (no idea where my filters have
>filtered it off to) ...
>
>Anyway, what I find works very well is the "Open Session in View"
>pattern/filter: http://www.hibernate.org/43.html
>
>A session is opened for the entire request and automatically closed.
>
>Another thing worth looking into is possibly the Spring Framework. I've
>played around with it briefly ... from memory, there's also a tutorial
>available for using Tapestry + Spring + Hibernate on their Wiki.
>
>Hope this helps.
>
>  - John
>
>On Tue, 2004-01-06 at 20:19, Eric Schneider wrote:
>  
>
>>John,
>>
>>Try creating the session in prepareForRender(), see if that makes a
>>difference.
>>
>>Cheers,
>>Eric
>>
>>----- Original Message ----- 
>>From: "Jamie Orchard-Hays" <ja...@dang.com>
>>To: "Tapestry users" <ta...@jakarta.apache.org>;
>><st...@jhlconsulting.com>
>>Sent: Tuesday, January 06, 2004 2:11 PM
>>Subject: Re: hibernate/tapestry & lazy initalization
>>
>>
>>    
>>
>>>I don't think initialize() is where you want to do this. That's where you
>>>set properties to the default values you want when you are *finished* with
>>>the page (usually null).
>>>
>>>
>>>----- Original Message ----- 
>>>From: "John Studarus" <st...@jhlconsulting.com>
>>>To: <ta...@jakarta.apache.org>
>>>Sent: Tuesday, January 06, 2004 1:29 PM
>>>Subject: hibernate/tapestry & lazy initalization
>>>
>>>
>>>      
>>>
>>>>  I've been using Tapestry with Hibernate (and Tomcat 5)
>>>>for a few months now with great results.  I recently ran
>>>>into a problem that I am curious if anyone else has
>>>>encountered.
>>>>  I've been rely upon Hibernate to populate objects
>>>>for me from the database via OGNL calls in Tapestry.
>>>>However, at times, Tapestry calls Hibernate objects
>>>>(like the source in a foreach) without hitting any of
>>>>my code.  This means I don't have the opportunity to
>>>>create a Session for Hibernate to use and I end up
>>>>with an exception.
>>>>  I need to be able to create a session object
>>>>before Tapestry makes any calls into my Hibernate
>>>>objects.  Any ideas on how this could be done?  I've
>>>>created the Hibernate sessions in both the Tapestry
>>>>page constructor and inside the initialize call.  I
>>>>get the exception when Tapestry pulls up the Hibernate
>>>>object.  Or I wonder if Tapestry is doing its work
>>>>in a different thread than my code and can't see
>>>>my Thread specific session.
>>>>  This only effects Tapestry/Hibernate when lazy initalization
>>>>is turned on.  I have a feeling that most people use
>>>>lazy initalization when using Tapestry and Hibernate together
>>>>but the performance hit is too great for me to leave lazy
>>>>initalization turned on (difference between something taking
>>>>1.5 hours or 30 seconds...).
>>>>  There was a post out there about using a Filter - anyone
>>>>every tried that?  Any Hibernate/Tapestry experts out there?
>>>>  Thanks,
>>>>
>>>>        John
>>>>
>>>>net.sf.hibernate.LazyInitializationException: Failed to lazily
>>>>        
>>>>
>>initialize
>>    
>>
>>>a collection - no Session
>>>      
>>>
>>>>        at
>>>>        
>>>>
>>net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollec
>>    
>>
>>>tion.java:167)
>>>      
>>>
>>>>        at
>>>>        
>>>>
>>net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.j
>>    
>>
>>>ava:64)
>>>      
>>>
>>>>        at net.sf.hibernate.collection.Set.size(Set.java:114)
>>>>        at
>>>>        
>>>>
>>org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:
>>    
>>
>>>568)
>>>      
>>>
>>>>        at
>>>>        
>>>>
>>>org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
>>>      
>>>
>>>>        at
>>>>        
>>>>
>>>org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
>>>      
>>>
>>>>        at
>>>>        
>>>>
>>>org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
>>>      
>>>
>>>>...  cut ...
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>>>>        
>>>>



---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: hibernate/tapestry & lazy initalization

Posted by John Meredith <ps...@t-online.de>.
Hi John,

Somehow I missed the original post (no idea where my filters have
filtered it off to) ...

Anyway, what I find works very well is the "Open Session in View"
pattern/filter: http://www.hibernate.org/43.html

A session is opened for the entire request and automatically closed.

Another thing worth looking into is possibly the Spring Framework. I've
played around with it briefly ... from memory, there's also a tutorial
available for using Tapestry + Spring + Hibernate on their Wiki.

Hope this helps.

  - John

On Tue, 2004-01-06 at 20:19, Eric Schneider wrote:
> John,
> 
> Try creating the session in prepareForRender(), see if that makes a
> difference.
> 
> Cheers,
> Eric
> 
> ----- Original Message ----- 
> From: "Jamie Orchard-Hays" <ja...@dang.com>
> To: "Tapestry users" <ta...@jakarta.apache.org>;
> <st...@jhlconsulting.com>
> Sent: Tuesday, January 06, 2004 2:11 PM
> Subject: Re: hibernate/tapestry & lazy initalization
> 
> 
> > I don't think initialize() is where you want to do this. That's where you
> > set properties to the default values you want when you are *finished* with
> > the page (usually null).
> >
> >
> > ----- Original Message ----- 
> > From: "John Studarus" <st...@jhlconsulting.com>
> > To: <ta...@jakarta.apache.org>
> > Sent: Tuesday, January 06, 2004 1:29 PM
> > Subject: hibernate/tapestry & lazy initalization
> >
> >
> > >
> > >   I've been using Tapestry with Hibernate (and Tomcat 5)
> > > for a few months now with great results.  I recently ran
> > > into a problem that I am curious if anyone else has
> > > encountered.
> > >   I've been rely upon Hibernate to populate objects
> > > for me from the database via OGNL calls in Tapestry.
> > > However, at times, Tapestry calls Hibernate objects
> > > (like the source in a foreach) without hitting any of
> > > my code.  This means I don't have the opportunity to
> > > create a Session for Hibernate to use and I end up
> > > with an exception.
> > >   I need to be able to create a session object
> > > before Tapestry makes any calls into my Hibernate
> > > objects.  Any ideas on how this could be done?  I've
> > > created the Hibernate sessions in both the Tapestry
> > > page constructor and inside the initialize call.  I
> > > get the exception when Tapestry pulls up the Hibernate
> > > object.  Or I wonder if Tapestry is doing its work
> > > in a different thread than my code and can't see
> > > my Thread specific session.
> > >   This only effects Tapestry/Hibernate when lazy initalization
> > > is turned on.  I have a feeling that most people use
> > > lazy initalization when using Tapestry and Hibernate together
> > > but the performance hit is too great for me to leave lazy
> > > initalization turned on (difference between something taking
> > > 1.5 hours or 30 seconds...).
> > >   There was a post out there about using a Filter - anyone
> > > every tried that?  Any Hibernate/Tapestry experts out there?
> > >   Thanks,
> > >
> > >         John
> > >
> > > net.sf.hibernate.LazyInitializationException: Failed to lazily
> initialize
> > a collection - no Session
> > >         at
> >
> net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollec
> > tion.java:167)
> > >         at
> >
> net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.j
> > ava:64)
> > >         at net.sf.hibernate.collection.Set.size(Set.java:114)
> > >         at
> >
> org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:
> > 568)
> > >         at
> > org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
> > >         at
> > org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
> > >         at
> > org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
> > > ...  cut ...
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
-- 
John Meredith <ps...@t-online.de>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: hibernate/tapestry & lazy initalization

Posted by Eric Schneider <er...@centralparksoftware.com>.
John,

Try creating the session in prepareForRender(), see if that makes a
difference.

Cheers,
Eric

----- Original Message ----- 
From: "Jamie Orchard-Hays" <ja...@dang.com>
To: "Tapestry users" <ta...@jakarta.apache.org>;
<st...@jhlconsulting.com>
Sent: Tuesday, January 06, 2004 2:11 PM
Subject: Re: hibernate/tapestry & lazy initalization


> I don't think initialize() is where you want to do this. That's where you
> set properties to the default values you want when you are *finished* with
> the page (usually null).
>
>
> ----- Original Message ----- 
> From: "John Studarus" <st...@jhlconsulting.com>
> To: <ta...@jakarta.apache.org>
> Sent: Tuesday, January 06, 2004 1:29 PM
> Subject: hibernate/tapestry & lazy initalization
>
>
> >
> >   I've been using Tapestry with Hibernate (and Tomcat 5)
> > for a few months now with great results.  I recently ran
> > into a problem that I am curious if anyone else has
> > encountered.
> >   I've been rely upon Hibernate to populate objects
> > for me from the database via OGNL calls in Tapestry.
> > However, at times, Tapestry calls Hibernate objects
> > (like the source in a foreach) without hitting any of
> > my code.  This means I don't have the opportunity to
> > create a Session for Hibernate to use and I end up
> > with an exception.
> >   I need to be able to create a session object
> > before Tapestry makes any calls into my Hibernate
> > objects.  Any ideas on how this could be done?  I've
> > created the Hibernate sessions in both the Tapestry
> > page constructor and inside the initialize call.  I
> > get the exception when Tapestry pulls up the Hibernate
> > object.  Or I wonder if Tapestry is doing its work
> > in a different thread than my code and can't see
> > my Thread specific session.
> >   This only effects Tapestry/Hibernate when lazy initalization
> > is turned on.  I have a feeling that most people use
> > lazy initalization when using Tapestry and Hibernate together
> > but the performance hit is too great for me to leave lazy
> > initalization turned on (difference between something taking
> > 1.5 hours or 30 seconds...).
> >   There was a post out there about using a Filter - anyone
> > every tried that?  Any Hibernate/Tapestry experts out there?
> >   Thanks,
> >
> >         John
> >
> > net.sf.hibernate.LazyInitializationException: Failed to lazily
initialize
> a collection - no Session
> >         at
>
net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollec
> tion.java:167)
> >         at
>
net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.j
> ava:64)
> >         at net.sf.hibernate.collection.Set.size(Set.java:114)
> >         at
>
org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:
> 568)
> >         at
> org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
> >         at
> org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
> >         at
> org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
> > ...  cut ...
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
> >
> >
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: hibernate/tapestry & lazy initalization

Posted by Jamie Orchard-Hays <ja...@dang.com>.
I don't think initialize() is where you want to do this. That's where you
set properties to the default values you want when you are *finished* with
the page (usually null).


----- Original Message ----- 
From: "John Studarus" <st...@jhlconsulting.com>
To: <ta...@jakarta.apache.org>
Sent: Tuesday, January 06, 2004 1:29 PM
Subject: hibernate/tapestry & lazy initalization


>
>   I've been using Tapestry with Hibernate (and Tomcat 5)
> for a few months now with great results.  I recently ran
> into a problem that I am curious if anyone else has
> encountered.
>   I've been rely upon Hibernate to populate objects
> for me from the database via OGNL calls in Tapestry.
> However, at times, Tapestry calls Hibernate objects
> (like the source in a foreach) without hitting any of
> my code.  This means I don't have the opportunity to
> create a Session for Hibernate to use and I end up
> with an exception.
>   I need to be able to create a session object
> before Tapestry makes any calls into my Hibernate
> objects.  Any ideas on how this could be done?  I've
> created the Hibernate sessions in both the Tapestry
> page constructor and inside the initialize call.  I
> get the exception when Tapestry pulls up the Hibernate
> object.  Or I wonder if Tapestry is doing its work
> in a different thread than my code and can't see
> my Thread specific session.
>   This only effects Tapestry/Hibernate when lazy initalization
> is turned on.  I have a feeling that most people use
> lazy initalization when using Tapestry and Hibernate together
> but the performance hit is too great for me to leave lazy
> initalization turned on (difference between something taking
> 1.5 hours or 30 seconds...).
>   There was a post out there about using a Filter - anyone
> every tried that?  Any Hibernate/Tapestry experts out there?
>   Thanks,
>
>         John
>
> net.sf.hibernate.LazyInitializationException: Failed to lazily initialize
a collection - no Session
>         at
net.sf.hibernate.collection.PersistentCollection.initialize(PersistentCollec
tion.java:167)
>         at
net.sf.hibernate.collection.PersistentCollection.read(PersistentCollection.j
ava:64)
>         at net.sf.hibernate.collection.Set.size(Set.java:114)
>         at
org.apache.tapestry.Tapestry$CollectionIteratorAdaptor.coerce(Tapestry.java:
568)
>         at
org.apache.tapestry.Tapestry.coerceToIterator(Tapestry.java:864)
>         at
org.apache.tapestry.components.Foreach.getSourceData(Foreach.java:113)
>         at
org.apache.tapestry.components.Foreach.renderComponent(Foreach.java:126)
> ...  cut ...
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: tapestry-user-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org