You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Mounir Benzid <mb...@meetingmasters.de> on 2012/07/26 11:44:54 UTC

Open session in view (JPA, struts2, Spring 3, Hibernate4)

Because of a "limitation" (which is rather a bug) of Hibernate 4, I need 
to switch to an open-session-in-view pattern in struts2


I was hoping that setting the right spring configuration in my web.xml 
would do the trick (see below)

The session still dies before the view layer (ognl) has any chance to 
lazy fetch from the database.

Is there anything struts-specific to make OSIV work?


I use Spring 3 and the EntityManager is from my JPA provider (hibernate).

- Mounir



   <filter>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
         <filter-class>
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
         </filter-class>
         <init-param>
<param-name>entityManagerFactory</param-name>
<param-value>entityManagerFactory</param-value>
         </init-param>
     </filter>
     <filter-mapping>
<filter-name>OpenEntityManagerInViewFilter</filter-name>
         <url-pattern>/public/*</url-pattern>
     </filter-mapping>

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


RE: Open session in view (JPA, struts2, Spring 3, Hibernate4)

Posted by Martin Gainty <mg...@hotmail.com>.
How do you want Spring to find the Action?
autowire by name?
autowire by type?

IF you want Spring to create the Action then...

However, sometimes you might want the bean to be completely managed by 
Spring. 
(This is useful, for example, if you wish to apply more complex AOP or 
Spring-enabled technologies, such as Acegi, to your beans.)
To do this, all you 
have to do is configure the bean in your Spring applicationContext.xml 
and then 
change the class attribute from your Action in the 
struts.xml to use the bean name defined in Spring instead of the class 
name.
Your struts.xml file would then have the Action class attributes 
changed..as defined here


struts.xml
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
    <include file="struts-default.xml"/>

    <package name="default" extends="struts-default">
        <action name="foo" class="com.acme.Foo">
            <result>foo.ftl</result>
        </action>
    </package>

    <package name="secure" namespace="/secure" extends="default">
        <action name="bar" class="bar">
            <result>bar.ftl</result>
        </action>
    </package>
</struts>
Martin 
______________________________________________ 
Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> Date: Mon, 20 Aug 2012 14:02:36 +0200
> Subject: Re: Open session in view (JPA, struts2, Spring 3, Hibernate4)
> From: lukaszlenart@apache.org
> To: user@struts.apache.org
> 
> 2012/8/9 Mounir Benzid <mb...@meetingmasters.de>:
> > sorry for the late response. web.xml ---> http://pastebin.com/XPiQ3ZJB
> >
> > I guess the problem might be that the transaction boundary starts and ends
> > within the controller class I wrote to manage entities. The action itself
> > doesn't participate in the transaction. If my understanding is correct then
> > the OSIV pattern needs an active transaction. Should I let spring manage the
> > action in order to propagate the transaction to it?
> 
> Why not to extend OSIV to /* ?
> 
> 
> Regards
> -- 
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  

Re: Open session in view (JPA, struts2, Spring 3, Hibernate4)

Posted by Lukasz Lenart <lu...@apache.org>.
2012/8/9 Mounir Benzid <mb...@meetingmasters.de>:
> sorry for the late response. web.xml ---> http://pastebin.com/XPiQ3ZJB
>
> I guess the problem might be that the transaction boundary starts and ends
> within the controller class I wrote to manage entities. The action itself
> doesn't participate in the transaction. If my understanding is correct then
> the OSIV pattern needs an active transaction. Should I let spring manage the
> action in order to propagate the transaction to it?

Why not to extend OSIV to /* ?


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

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


RE: Open session in view (JPA, struts2, Spring 3, Hibernate4)

Posted by Martin Gainty <mg...@hotmail.com>.


HTTP Session captures dynamic Session variables from Session initialisation to Session invalidation or timeout
a Database Transaction captures database information from Start to (commit or rollback)
Is there a reason why you would want your Session to be disconnected from the Database Transaction?

Martin 
______________________________________________ 
Jogi és Bizalmassági kinyilatkoztatás/Verzicht und Vertraulichkeitanmerkung/Note de déni et de confidentialité
 Ez az
üzenet bizalmas.  Ha nem ön az akinek szánva volt, akkor kérjük, hogy
jelentse azt nekünk vissza. Semmiféle továbbítása vagy másolatának
készítése nem megengedett.  Ez az üzenet csak ismeret cserét szolgál és
semmiféle jogi alkalmazhatósága sincs.  Mivel az electronikus üzenetek
könnyen megváltoztathatóak, ezért minket semmi felelöség nem terhelhet
ezen üzenet tartalma miatt.

Diese Nachricht ist vertraulich. Sollten Sie nicht der vorgesehene Empfaenger sein, so bitten wir hoeflich um eine Mitteilung. Jede unbefugte Weiterleitung oder Fertigung einer Kopie ist unzulaessig. Diese Nachricht dient lediglich dem Austausch von Informationen und entfaltet keine rechtliche Bindungswirkung. Aufgrund der leichten Manipulierbarkeit von E-Mails koennen wir keine Haftung fuer den Inhalt uebernehmen.
Ce message est confidentiel et peut être privilégié. Si vous n'êtes pas le destinataire prévu, nous te demandons avec bonté que pour satisfaire informez l'expéditeur. N'importe quelle diffusion non autorisée ou la copie de ceci est interdite. Ce message sert à l'information seulement et n'aura pas n'importe quel effet légalement obligatoire. Étant donné que les email peuvent facilement être sujets à la manipulation, nous ne pouvons accepter aucune responsabilité pour le contenu fourni.


> Date: Thu, 9 Aug 2012 09:20:30 +0200
> From: mb@meetingmasters.de
> To: user@struts.apache.org
> Subject: Re: Open session in view (JPA, struts2, Spring 3, Hibernate4)
> 
> Am 7/26/2012 4:39 PM, schrieb Maurizio Cucchiara:
> > Did you try to extend the url mapping to the whole root?
> >
> > f.e.:  <url-pattern>/*</url-**pattern>
> >
> >
> > Twitter     :http://www.twitter.com/m_cucchiara
> > G+          :https://plus.google.com/107903711540963855921
> > Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
> >
> > Maurizio Cucchiara
> >
> >
> > On 26 July 2012 15:36, Łukasz Lenart <lu...@googlemail.com> wrote:
> >
> >> Could you show the whole web.xml ?
> >>
> >>
> >> Regards
> >> --
> >> Łukasz
> >> mobile +48 606 323 122 http://www.lenart.org.pl/
> >> Warszawa JUG conference - Confitura http://confitura.pl/
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> >> For additional commands, e-mail: user-help@struts.apache.org
> >>
> >>
> >
> 
> Łukasz, Maurizio
> 
> sorry for the late response. web.xml ---> http://pastebin.com/XPiQ3ZJB
> 
> I guess the problem might be that the transaction boundary starts and ends within the controller class I wrote to manage entities. The action itself doesn't participate in the transaction. If my understanding is correct then the OSIV pattern needs an active transaction. Should I let spring manage the action in order to propagate the transaction to it?
> 
> Mounir
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
 		 	   		  

Re: Open session in view (JPA, struts2, Spring 3, Hibernate4)

Posted by Mounir Benzid <mb...@meetingmasters.de>.
Am 7/26/2012 4:39 PM, schrieb Maurizio Cucchiara:
> Did you try to extend the url mapping to the whole root?
>
> f.e.:  <url-pattern>/*</url-**pattern>
>
>
> Twitter     :http://www.twitter.com/m_cucchiara
> G+          :https://plus.google.com/107903711540963855921
> Linkedin    :http://www.linkedin.com/in/mauriziocucchiara
>
> Maurizio Cucchiara
>
>
> On 26 July 2012 15:36, Łukasz Lenart <lu...@googlemail.com> wrote:
>
>> Could you show the whole web.xml ?
>>
>>
>> Regards
>> --
>> Łukasz
>> mobile +48 606 323 122 http://www.lenart.org.pl/
>> Warszawa JUG conference - Confitura http://confitura.pl/
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>

Łukasz, Maurizio

sorry for the late response. web.xml ---> http://pastebin.com/XPiQ3ZJB

I guess the problem might be that the transaction boundary starts and ends within the controller class I wrote to manage entities. The action itself doesn't participate in the transaction. If my understanding is correct then the OSIV pattern needs an active transaction. Should I let spring manage the action in order to propagate the transaction to it?

Mounir




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


Re: Open session in view (JPA, struts2, Spring 3, Hibernate4)

Posted by Maurizio Cucchiara <mc...@apache.org>.
Did you try to extend the url mapping to the whole root?

f.e.:  <url-pattern>/*</url-**pattern>


Twitter     :http://www.twitter.com/m_cucchiara
G+          :https://plus.google.com/107903711540963855921
Linkedin    :http://www.linkedin.com/in/mauriziocucchiara

Maurizio Cucchiara


On 26 July 2012 15:36, Łukasz Lenart <lu...@googlemail.com> wrote:

> Could you show the whole web.xml ?
>
>
> Regards
> --
> Łukasz
> mobile +48 606 323 122 http://www.lenart.org.pl/
> Warszawa JUG conference - Confitura http://confitura.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: Open session in view (JPA, struts2, Spring 3, Hibernate4)

Posted by Łukasz Lenart <lu...@googlemail.com>.
Could you show the whole web.xml ?


Regards
-- 
Łukasz
mobile +48 606 323 122 http://www.lenart.org.pl/
Warszawa JUG conference - Confitura http://confitura.pl/

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