Page 4 of 4 FirstFirst ... 234
Results 31 to 34 of 34

Thread: LazyInitializationException Hibernate Spring Help!!!

  1. #31
    Join Date
    Jan 2010
    Posts
    1

    Red face it works

    Quote 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.

  2. #32

    Default 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

  3. #33

    Default 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

  4. #34
    Join Date
    Oct 2011
    Posts
    13

    Default

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

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •