Re: [Resin-interest] Hibernate lazy loading with Quercus

2009-11-26 Thread Vincent LAUGIER
Title: Vincent LAUGIER




Thank you very much !

the filter works fine.

We have added the following :

1. In web.xml :

    
   
TransactionPerRequestFilter
   
com.opticneo.filter.TransactionPerRequestFilter
    

    
   
TransactionPerRequestFilter
    *.php
    

2. And the filter itself :

import java.io.IOException;
import javax.ejb.EJBException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.transaction.SystemException;
import javax.transaction.UserTransaction;
import org.apache.log4j.Logger;

public class TransactionPerRequestFilter implements Filter {

    private static Logger log =
Logger.getLogger(TransactionPerRequestFilter.class);

    public void doFilter(ServletRequest request,
            ServletResponse response,
            FilterChain chain)
    throws IOException, ServletException {

        UserTransaction ut = null ;

        try {
            Context context = new InitialContext();
            ut = (javax.transaction.UserTransaction)
            context.lookup("java:comp/UserTransaction");

            ut.begin();
            chain.doFilter(request, response);
            ut.commit();

        } catch (Exception ex) {
            try {
                ut.rollback();
            } catch (SystemException syex) {
                throw new EJBException
                ("Rollback failed: " + syex.getMessage());
            }
            throw new EJBException 
            ("Transaction failed: " + ex.getMessage());
        }
    }

    public void init(FilterConfig filterConfig) throws ServletException
{
        log.debug("Initializing filter...");        
    }

    public void destroy() {}

}







  

   Vincent LAUGIER 
Email : vincent.laug...@helmet.fr
Téléphone : + 33 (0)1 75 43 92 52
Fax : + 33 (0)1 79 75 01 12 (monfax.com)
  


  




Michael Rusch a écrit :

   >> Seems that the objects no longer have the association with valid 
session, so either the Session or PersistenceManager should be kept 
around to fill the objects in upon use. Forcing eager load could also be 
used I think.
 >>
 >> Alex.

Just noting that this can be done on the configuration level, or you can 
do it using joins when you query for your objects.


 > I assume the easiest route here is to use a Filter to achieve
 > "session/transaction per request".
 >
 >  

Along those same lines, you might also want to check out the "Open 
Session in View" pattern, which is mentioned in a number of places in 
the Hibernate docs:

https://www.hibernate.org/43.html

Michael

  
  
Alex wrote (2009-11-24 06:01):


  
Hello,

we try to do the following on our php/EJB3 application :
	• find a given client from its lastname using a stateless bean ()
	• load his orders using the getter

[code]
$clients = $client_eao->findBySample($sample_client,false,false);
var_dump($clients[0]->getOrders());
[/code]


  
  Seems that the objects no longer have the association with valid session, so either the Session or PersistenceManager should be kept around to fill the objects in upon use. Forcing eager load could also be used I think.

Alex.
  
  

I assume the easiest route here is to use a Filter to achieve 
"session/transaction per request".

 



  
We get the usual LazyInitializationException :
[10:41:03.300] {http--8080-6$31582617} org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.opticneo.entity.client.Client.orders, no session or session was closed

If we were using Hessian, before returning the list of clients we would have made a copy of the list (using beanlib) before it is serialized (in ordre to avoid LazyInitializationException)
With Quercus, we do not have to do this. Good ! But we face the LazyInitializationException again when trying to access the complex attributes.

What is the best way to handle this ? (maybe by taking control over the transaction from the php)

Thanks for your help.

Regards

-- 
Vincent LAUGIER 


  





___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

  
  

___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


  



___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Hibernate lazy loading with Quercus

2009-11-24 Thread Michael Rusch
 >> Seems that the objects no longer have the association with valid 
session, so either the Session or PersistenceManager should be kept 
around to fill the objects in upon use. Forcing eager load could also be 
used I think.
 >>
 >> Alex.

Just noting that this can be done on the configuration level, or you can 
do it using joins when you query for your objects.


 > I assume the easiest route here is to use a Filter to achieve
 > "session/transaction per request".
 >
 >  

Along those same lines, you might also want to check out the "Open 
Session in View" pattern, which is mentioned in a number of places in 
the Hibernate docs:

https://www.hibernate.org/43.html

Michael

> Alex wrote (2009-11-24 06:01):
>>> Hello,
>>>
>>> we try to do the following on our php/EJB3 application :
>>> • find a given client from its lastname using a stateless bean ()
>>> • load his orders using the getter
>>>
>>> [code]
>>> $clients = $client_eao->findBySample($sample_client,false,false);
>>> var_dump($clients[0]->getOrders());
>>> [/code]
>>> 
>>
>> Seems that the objects no longer have the association with valid session, so 
>> either the Session or PersistenceManager should be kept around to fill the 
>> objects in upon use. Forcing eager load could also be used I think.
>>
>> Alex.
>>   
> 
> I assume the easiest route here is to use a Filter to achieve 
> "session/transaction per request".
> 
>  
> 
>>> We get the usual LazyInitializationException :
>>> [10:41:03.300] {http--8080-6$31582617} 
>>> org.hibernate.LazyInitializationException: failed to lazily initialize a 
>>> collection of role: com.opticneo.entity.client.Client.orders, no session or 
>>> session was closed
>>>
>>> If we were using Hessian, before returning the list of clients we would 
>>> have made a copy of the list (using beanlib) before it is serialized (in 
>>> ordre to avoid LazyInitializationException)
>>> With Quercus, we do not have to do this. Good ! But we face the 
>>> LazyInitializationException again when trying to access the complex 
>>> attributes.
>>>
>>> What is the best way to handle this ? (maybe by taking control over the 
>>> transaction from the php)
>>>
>>> Thanks for your help.
>>>
>>> Regards
>>>
>>> -- 
>>> Vincent LAUGIER 
>>> 
> 
> 
> 
> 
> 
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest


___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Hibernate lazy loading with Quercus

2009-11-23 Thread Mattias Jiderhamn

Alex wrote (2009-11-24 06:01):

Hello,

we try to do the following on our php/EJB3 application :
• find a given client from its lastname using a stateless bean ()
• load his orders using the getter

[code]
$clients = $client_eao->findBySample($sample_client,false,false);
var_dump($clients[0]->getOrders());
[/code]



Seems that the objects no longer have the association with valid session, so 
either the Session or PersistenceManager should be kept around to fill the 
objects in upon use. Forcing eager load could also be used I think.

Alex.
  


I assume the easiest route here is to use a Filter to achieve 
"session/transaction per request".





We get the usual LazyInitializationException :
[10:41:03.300] {http--8080-6$31582617} 
org.hibernate.LazyInitializationException: failed to lazily initialize a 
collection of role: com.opticneo.entity.client.Client.orders, no session or 
session was closed

If we were using Hessian, before returning the list of clients we would have 
made a copy of the list (using beanlib) before it is serialized (in ordre to 
avoid LazyInitializationException)
With Quercus, we do not have to do this. Good ! But we face the 
LazyInitializationException again when trying to access the complex attributes.

What is the best way to handle this ? (maybe by taking control over the 
transaction from the php)

Thanks for your help.

Regards

--
Vincent LAUGIER 




___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


Re: [Resin-interest] Hibernate lazy loading with Quercus

2009-11-23 Thread Alex
> Hello,
> 
> we try to do the following on our php/EJB3 application :
>   • find a given client from its lastname using a stateless bean ()
>   • load his orders using the getter
> 
> [code]
> $clients = $client_eao->findBySample($sample_client,false,false);
> var_dump($clients[0]->getOrders());
> [/code]

Seems that the objects no longer have the association with valid session, so 
either the Session or PersistenceManager should be kept around to fill the 
objects in upon use. Forcing eager load could also be used I think.

Alex.
> 
> We get the usual LazyInitializationException :
> [10:41:03.300] {http--8080-6$31582617} 
> org.hibernate.LazyInitializationException: failed to lazily initialize a 
> collection of role: com.opticneo.entity.client.Client.orders, no session or 
> session was closed
> 
> If we were using Hessian, before returning the list of clients we would have 
> made a copy of the list (using beanlib) before it is serialized (in ordre to 
> avoid LazyInitializationException)
> With Quercus, we do not have to do this. Good ! But we face the 
> LazyInitializationException again when trying to access the complex 
> attributes.
> 
> What is the best way to handle this ? (maybe by taking control over the 
> transaction from the php)
> 
> Thanks for your help.
> 
> Regards
> 
> -- 
> Vincent LAUGIER 
> Email : vincent.laug...@helmet.fr
> Téléphone : + 33 (0)1 75 43 92 52
> Fax : + 33 (0)1 79 75 01 12 (monfax.com)
>  
> ___
> resin-interest mailing list
> resin-interest@caucho.com
> http://maillist.caucho.com/mailman/listinfo/resin-interest




___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest


[Resin-interest] Hibernate lazy loading with Quercus

2009-11-23 Thread Vincent LAUGIER
Title: Vincent LAUGIER




Hello,

we try to do the following on our php/EJB3 application :

  find a given client from its lastname using a stateless bean ()
  
  load his orders using the getter


[code]
$clients = $client_eao->findBySample($sample_client,false,false);
var_dump($clients[0]->getOrders());
[/code]

We get the usual LazyInitializationException :
[10:41:03.300] {http--8080-6$31582617}
org.hibernate.LazyInitializationException: failed to lazily initialize
a collection of role: com.opticneo.entity.client.Client.orders, no
session or session was closed

If we were using Hessian, before returning the list of clients we would
have made a copy of the list (using beanlib) before it is serialized
(in ordre to avoid LazyInitializationException)
With Quercus, we do not have to do this. Good ! But we face the
LazyInitializationException again when trying to access the complex
attributes.

What is the best way to handle this ? (maybe by taking control over the
transaction from the php)

Thanks for your help.

Regards

-- 




  

   Vincent LAUGIER 
Email : vincent.laug...@helmet.fr
Téléphone : + 33 (0)1 75 43 92 52
Fax : + 33 (0)1 79 75 01 12 (monfax.com)
  


  




___
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest