Announcement Announcement Module
Collapse
No announcement yet.
LazyInitializationException Hibernate Spring Help!!! Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #31
    it works

    Originally posted by logixplayer View Post
    I see what you are saying and incidentally there are 2 ways to "keep the session alive".
    One is what you are saying, using the OpenSessionInViewInterceptor
    The second is: OpenEntityManagerInViewFilter.

    Both can work, I think the OpenSessionInViewFilter would be nicer to use...
    anyway I did this:
    Code:
    	<filter>
    	    <!-- <filter-name>Spring OpenEntityManagerInViewFilter</filter-name> -->
    	    <filter-name>OpenEntityManagerInViewFilter</filter-name>
    	    <filter-class>
    	        org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
    	    </filter-class>
    	      <init-param>
    			<param-name>singleSession</param-name>
    			<param-value>false</param-value>
    		</init-param>
    		<init-param>  
    			<param-name>flushMode</param-name>  
    			<param-value>AUTO</param-value>  
    		</init-param> 
    	    
    	</filter>
    but it still did not work!

    Try this:

    This class in some package:

    public class HibernateOpenSessionFilter extends OpenSessionInViewFilter {

    @Override
    protected Session getSession(SessionFactory sessionFactory) throws DataAccessResourceFailureException {
    Session session = SessionFactoryUtils.getSession(sessionFactory, true);
    session.setFlushMode(FlushMode.AUTO);
    return session;
    }

    @Override
    protected void closeSession(Session session, SessionFactory sessionFactory) {
    try {
    try {
    if (session != null && session.isOpen() && session.isConnected()) {
    session.flush();
    }
    } catch (HibernateException e) {
    throw new CleanupFailureDataAccessException("Failed to flush session before close: " + e.getMessage(), e);
    }
    } finally {
    super.closeSession(session, sessionFactory);
    }
    }
    }


    and register this filter in web.xml

    <filter>
    <filter-name>HibernateOpenSessionFilter</filter-name>
    <filter-class>fantasyarena.filter.HibernateOpenSessionFilt er</filter-class>
    </filter>

    <filter-mapping>
    <filter-name>HibernateOpenSessionFilter</filter-name>
    <url-pattern>/*</url-pattern>
    </filter-mapping>


    I get this in work before ten minutes Itīs working nicely.

    Comment


    • #32
      Your solution works..

      @WarspiteCZ, Your solution works like charm without any complaints..
      I've been stuck with problem for so many days and finally resolved with your code.
      Thanks everyone and especially to 'WarspiteCZ' and 'logixplayer' for detail input..

      --velu

      Comment


      • #33
        Possible cause is a bug in Spring Transactions pre-3.0.1-RELEASE

        Hi all.

        I too spent way to much time trying to figure out what was wrong with my configuration, to discover my problem was due to a bug in Spring TX 3.0.0-RELEASE. The bug is fixed in 3.0.1-RELEASE, but is still a problem especially with dm Server up to verstion 2.0.1-RELEASE as it ships with Spring 3.0.0-RELEASE.


        See here for more details

        Regards,

        John

        Comment


        • #34
          @WarspiteCZ and @logixplayer thanks to your solutions! Got past this mess!

          Comment

          Working...
          X