myfaces-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Cagatay Civici <cagatay.civ...@gmail.com>
Subject Re: MyFaces Orchestra: How to Integrate with Hibernate ?
Date Fri, 12 Jun 2009 15:56:16 GMT
Are you sure you have the @Transactional around?

On Fri, Jun 12, 2009 at 4:52 PM, Alejandro Valdez <
alejandro.valdez@gmail.com> wrote:

> I'm sorry to insist (I don't like to beg for help), but I really can't
> figure out how Orchestra persistence context works with Hibernate, I'm
> just getting LazyInitializationException with the message "could not
> initialize proxy - no Session".
>
> Since my first e-mail I've implemented my DAO classes extending
> HibernateDaoSupport, but that didn't solve the issue.
>
> I think that there is something wrong with the way the application is
> layered (because the service/dao layer beans don't belong to any
> conversation):
>
> [conversation scope beans] -> [service layer] -> [dao layer] -> [hibernate]
>
> Or the persistence context feature from Orchestra isn't working.
>
> The (hibernate proxied) objects are correctly retrieved in the
> dao/service layers, but LazyInitializationException is thrown when
> they are accessed from a conversation scope beans.
>
> Well, hope someone can give me a hand.
>
> PS: Again, I'm sorry to insist.
>
>
>
> This is the kind of stack trace that I get:
>
> org.hibernate.LazyInitializationException: could not initialize proxy
> - no Session
>
>  org.hibernate.proxy.AbstractLazyInitializer.initialize(AbstractLazyInitializer.java:86)
>
>  org.hibernate.proxy.AbstractLazyInitializer.getImplementation(AbstractLazyInitializer.java:140)
>
>  org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer.invoke(JavassistLazyInitializer.java:190)
>
>  com.test.db.dto.AddressDto_$$_javassist_18.toString(AddressDto_$$_javassist_18.java)
>        com.sun.facelets.util.DevTools.writeVariables(DevTools.java:168)
>        com.sun.facelets.util.DevTools.writeVariables(DevTools.java:145)
>        com.sun.facelets.util.DevTools.debugHtml(DevTools.java:109)
>
>  com.sun.facelets.FaceletViewHandler.handleRenderException(FaceletViewHandler.java:671)
>
>  com.sun.facelets.FaceletViewHandler.renderView(FaceletViewHandler.java:639)
>
>  org.ajax4jsf.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:100)
>
>  org.ajax4jsf.application.AjaxViewHandler.renderView(AjaxViewHandler.java:176)
>
>  com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
>        com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
>        com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
>        javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)
>
>  org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
>        org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
>
>  org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:368)
>        org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:495)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:378)
>
>  org.springframework.security.intercept.web.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:109)
>
>  org.springframework.security.intercept.web.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:83)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.ui.SessionFixationProtectionFilter.doFilterHttp(SessionFixationProtectionFilter.java:67)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.ui.ExceptionTranslationFilter.doFilterHttp(ExceptionTranslationFilter.java:101)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.providers.anonymous.AnonymousProcessingFilter.doFilterHttp(AnonymousProcessingFilter.java:105)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.ui.rememberme.RememberMeProcessingFilter.doFilterHttp(RememberMeProcessingFilter.java:116)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.wrapper.SecurityContextHolderAwareRequestFilter.doFilterHttp(SecurityContextHolderAwareRequestFilter.java:91)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.ui.basicauth.BasicProcessingFilter.doFilterHttp(BasicProcessingFilter.java:174)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.ui.AbstractProcessingFilter.doFilterHttp(AbstractProcessingFilter.java:277)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.ui.logout.LogoutFilter.doFilterHttp(LogoutFilter.java:89)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.context.HttpSessionContextIntegrationFilter.doFilterHttp(HttpSessionContextIntegrationFilter.java:235)
>
>  org.springframework.security.ui.SpringSecurityFilter.doFilter(SpringSecurityFilter.java:53)
>
>  org.springframework.security.util.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:390)
>
>  org.springframework.security.util.FilterChainProxy.doFilter(FilterChainProxy.java:175)
>
>  org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:236)
>
>  org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:167)
>
>
>
>
>
>
>
> On Sat, Jun 6, 2009 at 12:46 PM, Alejandro
> Valdez<alejandro.valdez@gmail.com> wrote:
> > Hello list, I'm trying to integrate MyFaces Orchestra with Hibernate
> > (and Spring 2.5.6), I have already downloaded the example application
> > from http://code.google.com/p/myfaces-orchestra-goodies/ where an
> > HibernatePersistentContextFactory is provided, there is also an
> > example of a DAO that extends the Spring's HibernateDaoSupport class.
> >
> > I don't like the idea of implement my DAOs extending a Spring class,
> > so instead I wrote them as the example shown below.
> >
> > It seems that I'm doing something wrong, because I'm having two kind
> > of HibernateExceptions at different points of my application, in one
> > case it's telling that a collection is used in another session, in the
> > other case that a session is closed.
> >
> > The application is layered in this way: [conversation score beans] ->
> > [service layer] -> [dao layer] -> [hibernate]
> >
> > I can't figure out how HibernatePersistentContextFactory is assigning
> > the same session to the different DAOs in the dao layer, I think it
> > isn't happening and that is the cause of the exceptions.
> >
> > Hope someone can point me in the right direction.
> >
> > Examples:
> >
> > @Repository("userDAO")
> > public class HibernateUserDAO implements UserDAO {
> >
> >        @Autowired(required=true)
> >        private SessionFactory sessionFactory;
> >
> >        public HibernateUserDAO() {}
> >
> >        public Session getSession() {
> >                return sessionFactory.getCurrentSession();
> >        }
> >
> >        public List<UserDto> getAll() {
> >                Session session = getSession();
> >                Query query = session.createQuery("FROM UserDto AS user
> ORDER BY
> > user.username ASC");
> >                return (List<UserDto>) query.list();
> >        }
> >
> > // other methods...
> > }
> >
> >
> > @Service("userService")
> > public class UserServiceImpl implements UserService {
> >
> >        @Autowired(required=true)
> >        private UserDAO userDAO;
> >
> >        @Transactional(readOnly = true)
> >        public List<UserDto> getAll(){
> >                return userDAO.getAll();
> >        }
> > // other methods...
> > }
> >
> >
> > @Component("userAdministrationBean")
> > @Scope("conversation.access")
> > @ConversationName("userAdministrationBean")
> > public class userAdministrationBean {
> >
> >        UserDto currentUser;
> >        @Autowired(required=true)
> >        private UserService userSvc;
> >
> >        public List<UserDto> getAllUsers() {
> >                return this.userSvc.getAll();
> >        }
> > // other methods...
> > }
> >
> >
> > If you are still reading this, this is the interesting part of the
> > Spring application-context.xml:
> >
> >    <tx:annotation-driven/>
> >
> >    <!-- 3. the "entity manager" manager -->
> >    <bean id="persistentContextConversationInterceptor"
> >
>  class="org.apache.myfaces.orchestra.conversation.spring.PersistenceContextConversationInterceptor">
> >      <property name="persistenceContextFactory"
> > ref="persistentContextFactory"/>
> >    </bean>
> >
> >    <!-- 4. conversation - persistence adapter -->
> >    <bean id="persistentContextFactory"
> >        class="my.application.db.HibernatePersistenceContextFactory">
> >      <property name="entityManagerFactory" ref="entityManagerFactory"/>
> >    </bean>
> >
> >        <bean id="transactionManager"
> > class="org.springframework.orm.hibernate3.HibernateTransactionManager">
> >                <property name="sessionFactory"
> ref="entityManagerFactory"/>
> >        </bean>
> >
> >        <bean id="entityManagerFactory"
> >
>  class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
> >                <property name="configLocation">
> >                        <value>classpath:hibernate.cfg.xml</value>
> >                </property>
> >        </bean>
> >
>

Mime
View raw message