Urrrgs found the problem ... literal error in the interceptor definition :P

> Hi guys,
>
> I have a problem with a training project using Struts² and Hibernate.
> To encapsulate the crosscutting concern of Session and Transaction 
> handling of Hibernate, I
> tried to write my own Interceptor for my Actions that touches my 
> Service layer.
>
> The interceptor is very simple ... here is the code:
>
> public class HibernateTransactionInterceptor implements Interceptor 
> {        public void destroy() {                  }
>
>    public void init() {
>    }
>
>    public String intercept(ActionInvocation arg0) throws Exception {
>        Session sess = DAOUtil.getSessionFactory().openSession();
>        Transaction tx = sess.beginTransaction();
>        tx.begin();
>        String result = arg0.invoke();
>        if (result.equals(ActionSupport.ERROR)) {
>            tx.rollback();
>        }
>        else {
>            tx.commit();
>        }
>        sess.close();
>        return result;          }
>
> }
>
> I registered this interceptor in my Struts² configuration and use it 
> for all my actions that touches my service layer.
> But it seems that this interceptor is not called in the interceptor 
> chain.
> Here is the Struts² package definition:
>
>    <package name="myPackage" namespace="/" extends="struts-default">
>        <interceptors>
>            <interceptor name="transactionInterceptor"
>                
> class="org.gartenshop.interceptors.HibernateTransactionInterseptor"/>
>        </interceptors>
>       ...
>       ...
>        <action name="LoadArticleInformation" 
> class="example.actions.LoadArticleInformation">                    
> <interceptor-ref name="transactionInterceptor"/>
>            <!-- we don't define a result here because the action is 
> handling the request directly-->
>        </action>
>       ...
>    </package>
>
> When I try to load an object from my database this way, I always get 
> an Exception from Hibernate with the message:
> *"load is not valid without active transaction".*
> In my opinion there is an active transaction bound to the Session 
> (because I opened it in the interceptor).
> I use DAOUtil.getSessionFactory().getCurrentSession() to get the 
> Session object opened by the Interceptor.
> Does anyone know where my fault is?
>
>
> Kind regards and thanks ahead
> Robert
>


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Java 
EE (J2EE) Programming with Passion!" group.
To post to this group, send email to 
java-ee-j2ee-programming-with-passion@googlegroups.com
To unsubscribe from this group, send email to 
java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to