You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by Jesper Zedlitz <jz...@informatik.uni-kiel.de> on 2008/03/01 15:21:03 UTC

RE: T5 PageTester problem (Spring and Hibernate)

Jonathan Barker wrote:
> I tried running your test, which gives a lazy-loading exception trying to
> access the Set<BeanB> from BeanA.  If you change your Hibernate mapping to
> use lazy="false" then the problem goes away.
> 
Unfortunately this is no option because the object tree is too large.

> I don't have a solution for you, but it's a similar problem to trying to
> use the HibernateTemplate outside of a web-app.  I have some command-line
> tools that look like:
> 
> ....
> this.session =
> SessionFactoryUtils.getSession(sessionFactory, true);
> 
> TransactionSynchronizationManager.bindResource(sessionFactory, new
> SessionHolder(session));
> 
The invocation of bindResource fails with:
java.lang.IllegalStateException: Already value
[org.springframework.orm.hibernate3.SessionHolder@46b90a] for key
[org.hibernate.impl.SessionFactoryImpl@11e67ac] bound to thread [main]

Jesper

-- 
Jesper Zedlitz                   Dept. for Computer Science, CAU of Kiel
Room 1108                        Communication Systems Research Group
                                 Phone:    +49-(0)431-880-7279
Christian-Albrechts-Platz 4      Fax:      +49-(0)431-880-7615
24098 Kiel - Germany             jze@informatik.uni-kiel.de


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


RE: T5 PageTester problem (Spring and Hibernate)

Posted by Jonathan Barker <jo...@gmail.com>.
> > I don't have a solution for you, but it's a similar problem to trying to
> > use the HibernateTemplate outside of a web-app.  I have some command-
> line
> > tools that look like:
> >
> > ....
> > this.session =
> > SessionFactoryUtils.getSession(sessionFactory, true);
> >
> > TransactionSynchronizationManager.bindResource(sessionFactory, new
> > SessionHolder(session));
> >
> The invocation of bindResource fails with:
> java.lang.IllegalStateException: Already value
> [org.springframework.orm.hibernate3.SessionHolder@46b90a] for key
> [org.hibernate.impl.SessionFactoryImpl@11e67ac] bound to thread [main]
> 
> Jesper

I tend to be too brief.  This was intended only as an avenue of
investigation.

The Spring Open Session In View Filter for Hibernate has similar lines to
what I wrote above.  Check out the source.  When you try to use DAO's
outside of a webapp, where you don't have the OSIV filter setting up
transaction plumbing for you, you need to do it manually.  I had a lot of
grief using common configuration between a web app and supporting
(command-line) tools until I figured that out.

In your case, I assume the OSIV filter is bypassed when testing so that
setup and cleanup is not done.

I am *speculating* that if you move the OSIV from web.xml/servlet container
level to one integrated into the internal Tapestry pipeline (as suggested in
my other followup), your problem may go away.  Honestly, I don't know.  It
seems reasonable but I don't know enough about the internals of
tapestry-ioc.

Take a look at the tapestry5-acegi code.  Acegi uses Spring and
tapestry5-acegi moves the configuration, including stuff that is normally
configured in web.xml, into AppModule.  It involved re-writing filters that
used to be wired in through web.xml configuration to be suitable for wiring
in through tapestry-ioc.

Here is a little snippet from tapestry5-acegis's SecurityModule that may
pique your curiosity:

    public static HttpServletRequestFilter
buildHttpSessionContextIntegrationFilter()
    throws Exception {
        HttpSessionContextIntegrationFilter filter = new
HttpSessionContextIntegrationFilter();
        filter.setContext(SecurityContextImpl.class);
        filter.setAllowSessionCreation(true);
        filter.setForceEagerSessionCreation(false);
        filter.afterPropertiesSet();
        return new HttpServletRequestFilterWrapper(filter);
    }


Or, I suppose you can give up on Spring and go for tapestry-hibernate :-)

Jon



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