You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Marcelo Lotif <ml...@gmail.com> on 2009/02/02 16:03:16 UTC

[T5] Problem using tapestry-hibernate inside a dispatcher

Hello all,

I have a dispatcher service in my application to control the user access to
pages they are not permitted to, or need to log in to do it. Besides, it
does an insert into the DB to record the user's movements into the system,
but just in case of success. It does well when we use the old way to access
the database (ResultSet, Statements and so on...)

Trying to move to tapestry-hibernate, we have to do this to inject the
hibernate session into the dispatcher service:

AccessController.java:
=======================================
    /* hibernate session */
    private Session _hibernateSession;

    public AccessController(ApplicationStateManager asm, Session
hibernateSession) {
        this._asm = asm;
        this._hibernateSession = hibernateSession;
    }

...
@CommitAfter
    public boolean dispatch(Request request, Response response) throws
IOException {
             ...
             if (canAccess) {
                    // Log do acesso.
                    this.doLog(request, visit, hibernateSession);
             }
             ...
     }

But when we try to persist the entity into the DB, it fails because the
annotation @CommitAfter has no effect here (I suppose). I tried to start and
commit a transaction manually and it did well, but when tapestry-hibernate
tried to do another query, it fails and gives the following exception:

[WARN] TapestryIOCModule.PerthreadManager Error invoking listener
org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl@fa1b2d:
Transaction not successfully started
org.hibernate.TransactionException: Transaction not successfully started
at
org.hibernate.transaction.JDBCTransaction.rollback(JDBCTransaction.java:183)
at
org.apache.tapestry5.internal.hibernate.HibernateSessionManagerImpl.threadDidCleanup(HibernateSessionManagerImpl.java:65)
at
org.apache.tapestry5.ioc.internal.services.PerthreadManagerImpl.cleanup(PerthreadManagerImpl.java:86)
at
org.apache.tapestry5.ioc.internal.RegistryImpl.cleanupThread(RegistryImpl.java:329)
at
org.apache.tapestry5.ioc.internal.RegistryWrapper.cleanupThread(RegistryWrapper.java:36)
at org.apache.tapestry5.TapestryFilter.doFilter(TapestryFilter.java:185)
at
org.mortbay.jetty.servlet.WebApplicationHandler$CachedChain.doFilter(WebApplicationHandler.java:821)
at
org.mortbay.jetty.servlet.WebApplicationHandler.dispatch(WebApplicationHandler.java:471)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:568)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1530)
at
org.mortbay.jetty.servlet.WebApplicationContext.handle(WebApplicationContext.java:633)
at org.mortbay.http.HttpContext.handle(HttpContext.java:1482)
at org.mortbay.http.HttpServer.service(HttpServer.java:909)
at org.mortbay.http.HttpConnection.service(HttpConnection.java:820)
at org.mortbay.http.HttpConnection.handleNext(HttpConnection.java:986)
at org.mortbay.http.HttpConnection.handle(HttpConnection.java:837)
at org.mortbay.http.SocketListener.handleConnection(SocketListener.java:245)
at org.mortbay.util.ThreadedServer.handle(ThreadedServer.java:357)
at org.mortbay.util.ThreadPool$PoolThread.run(ThreadPool.java:534)


anyone has any clue on how I can do this in a better way?

Thanks in advance!

-- 
Atenciosamente,

Marcelo Lotif
Programador Java e Tapestry
FIEC - Federação das Indústrias do Estado do Ceará
(85) 3421-5910

Re: [T5] Problem using tapestry-hibernate inside a dispatcher

Posted by Marcelo Lotif <ml...@gmail.com>.
I can't imagine how this can be easier, I'm very anxious to see!
T5.1 will be a huge release, and I'm sure it's new functionalities
will bring more users to this community.

On Mon, Feb 2, 2009 at 5:04 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> It's even easier in Tapestry 5.1., as you can advise a service (or set
> of services), rather than decorate.
>
> On Mon, Feb 2, 2009 at 9:48 AM, Marcelo Lotif <ml...@gmail.com>
> wrote:
> > Thanks Howard! It works beautifully!
> >
> > Just a note: I couldn't add this functionality directly to the
> dispatcher.
> > I've added it to the DAO instead. BTW, this is not a bad practice at all.
> >
> > Thank you!
> >
> > On Mon, Feb 2, 2009 at 1:12 PM, Howard Lewis Ship <hl...@gmail.com>
> wrote:
> >
> >> See the documentation:
> >>
> >> http://tapestry.apache.org/tapestry5/tapestry-hibernate/userguide.html
> >>
> >> for how to decorate your service to enable @CommitAfter.
> >>
> >> On Mon, Feb 2, 2009 at 8:06 AM, Massimo Lusetti <ml...@gmail.com>
> >> wrote:
> >> > On Mon, Feb 2, 2009 at 4:03 PM, Marcelo Lotif <ml...@gmail.com>
> >> wrote:
> >> >
> >> >> But when we try to persist the entity into the DB, it fails because
> the
> >> >> annotation @CommitAfter has no effect here (I suppose). I tried to
> start
> >> and
> >> >> commit a transaction manually and it did well, but when
> >> tapestry-hibernate
> >> >> tried to do another query, it fails and gives the following
> exception:
> >> >
> >> > If that's the case use HibernateSessionManager.
> >> >
> >> >
> >> > --
> >> > Massimo
> >> > http://meridio.blogspot.com
> >> >
> >> > ---------------------------------------------------------------------
> >> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> > For additional commands, e-mail: users-help@tapestry.apache.org
> >> >
> >> >
> >>
> >>
> >>
> >> --
> >> Howard M. Lewis Ship
> >>
> >> Creator Apache Tapestry and Apache HiveMind
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> >> For additional commands, e-mail: users-help@tapestry.apache.org
> >>
> >>
> >
> >
> > --
> > Atenciosamente,
> >
> > Marcelo Lotif
> > Programador Java e Tapestry
> > FIEC - Federação das Indústrias do Estado do Ceará
> > (85) 3421-5910
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator Apache Tapestry and Apache HiveMind
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Atenciosamente,

Marcelo Lotif
Programador Java e Tapestry
FIEC - Federação das Indústrias do Estado do Ceará
(85) 3421-5910

Re: [T5] Problem using tapestry-hibernate inside a dispatcher

Posted by Howard Lewis Ship <hl...@gmail.com>.
It's even easier in Tapestry 5.1., as you can advise a service (or set
of services), rather than decorate.

On Mon, Feb 2, 2009 at 9:48 AM, Marcelo Lotif <ml...@gmail.com> wrote:
> Thanks Howard! It works beautifully!
>
> Just a note: I couldn't add this functionality directly to the dispatcher.
> I've added it to the DAO instead. BTW, this is not a bad practice at all.
>
> Thank you!
>
> On Mon, Feb 2, 2009 at 1:12 PM, Howard Lewis Ship <hl...@gmail.com> wrote:
>
>> See the documentation:
>>
>> http://tapestry.apache.org/tapestry5/tapestry-hibernate/userguide.html
>>
>> for how to decorate your service to enable @CommitAfter.
>>
>> On Mon, Feb 2, 2009 at 8:06 AM, Massimo Lusetti <ml...@gmail.com>
>> wrote:
>> > On Mon, Feb 2, 2009 at 4:03 PM, Marcelo Lotif <ml...@gmail.com>
>> wrote:
>> >
>> >> But when we try to persist the entity into the DB, it fails because the
>> >> annotation @CommitAfter has no effect here (I suppose). I tried to start
>> and
>> >> commit a transaction manually and it did well, but when
>> tapestry-hibernate
>> >> tried to do another query, it fails and gives the following exception:
>> >
>> > If that's the case use HibernateSessionManager.
>> >
>> >
>> > --
>> > Massimo
>> > http://meridio.blogspot.com
>> >
>> > ---------------------------------------------------------------------
>> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> > For additional commands, e-mail: users-help@tapestry.apache.org
>> >
>> >
>>
>>
>>
>> --
>> Howard M. Lewis Ship
>>
>> Creator Apache Tapestry and Apache HiveMind
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
>> For additional commands, e-mail: users-help@tapestry.apache.org
>>
>>
>
>
> --
> Atenciosamente,
>
> Marcelo Lotif
> Programador Java e Tapestry
> FIEC - Federação das Indústrias do Estado do Ceará
> (85) 3421-5910
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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


Re: [T5] Problem using tapestry-hibernate inside a dispatcher

Posted by Marcelo Lotif <ml...@gmail.com>.
Thanks Howard! It works beautifully!

Just a note: I couldn't add this functionality directly to the dispatcher.
I've added it to the DAO instead. BTW, this is not a bad practice at all.

Thank you!

On Mon, Feb 2, 2009 at 1:12 PM, Howard Lewis Ship <hl...@gmail.com> wrote:

> See the documentation:
>
> http://tapestry.apache.org/tapestry5/tapestry-hibernate/userguide.html
>
> for how to decorate your service to enable @CommitAfter.
>
> On Mon, Feb 2, 2009 at 8:06 AM, Massimo Lusetti <ml...@gmail.com>
> wrote:
> > On Mon, Feb 2, 2009 at 4:03 PM, Marcelo Lotif <ml...@gmail.com>
> wrote:
> >
> >> But when we try to persist the entity into the DB, it fails because the
> >> annotation @CommitAfter has no effect here (I suppose). I tried to start
> and
> >> commit a transaction manually and it did well, but when
> tapestry-hibernate
> >> tried to do another query, it fails and gives the following exception:
> >
> > If that's the case use HibernateSessionManager.
> >
> >
> > --
> > Massimo
> > http://meridio.blogspot.com
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> > For additional commands, e-mail: users-help@tapestry.apache.org
> >
> >
>
>
>
> --
> Howard M. Lewis Ship
>
> Creator Apache Tapestry and Apache HiveMind
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>


-- 
Atenciosamente,

Marcelo Lotif
Programador Java e Tapestry
FIEC - Federação das Indústrias do Estado do Ceará
(85) 3421-5910

Re: [T5] Problem using tapestry-hibernate inside a dispatcher

Posted by Howard Lewis Ship <hl...@gmail.com>.
See the documentation:

http://tapestry.apache.org/tapestry5/tapestry-hibernate/userguide.html

for how to decorate your service to enable @CommitAfter.

On Mon, Feb 2, 2009 at 8:06 AM, Massimo Lusetti <ml...@gmail.com> wrote:
> On Mon, Feb 2, 2009 at 4:03 PM, Marcelo Lotif <ml...@gmail.com> wrote:
>
>> But when we try to persist the entity into the DB, it fails because the
>> annotation @CommitAfter has no effect here (I suppose). I tried to start and
>> commit a transaction manually and it did well, but when tapestry-hibernate
>> tried to do another query, it fails and gives the following exception:
>
> If that's the case use HibernateSessionManager.
>
>
> --
> Massimo
> http://meridio.blogspot.com
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: users-help@tapestry.apache.org
>
>



-- 
Howard M. Lewis Ship

Creator Apache Tapestry and Apache HiveMind

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


Re: [T5] Problem using tapestry-hibernate inside a dispatcher

Posted by Massimo Lusetti <ml...@gmail.com>.
On Mon, Feb 2, 2009 at 4:03 PM, Marcelo Lotif <ml...@gmail.com> wrote:

> But when we try to persist the entity into the DB, it fails because the
> annotation @CommitAfter has no effect here (I suppose). I tried to start and
> commit a transaction manually and it did well, but when tapestry-hibernate
> tried to do another query, it fails and gives the following exception:

If that's the case use HibernateSessionManager.


-- 
Massimo
http://meridio.blogspot.com

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