Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9133753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:32:31+00:00 2026-06-17T08:32:31+00:00

I have issue with Spring ‘s OpenSessionInViewFilter . My web.xml config looks like that:

  • 0

I have issue with Spring‘s OpenSessionInViewFilter. My web.xml config looks like that:

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>
        WEB-INF/applicationContext.xml
    </param-value>
</context-param>


<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
</listener>

<filter>
    <filter-name>Hibernate-OSIV pattern</filter-name>
    <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
    <init-param>
        <param-name>sessionFactoryBeanName</param-name>
        <param-value>sessionFactory</param-value>
    </init-param>
    <init-param>
        <param-name>singleSession</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
        <param-name>flushMode</param-name>
        <param-value>AUTO</param-value>
    </init-param>

</filter>
<filter-mapping>
    <filter-name>Hibernate-OSIV pattern</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

And my generic DAO looks like that:

public class BasicDaoImpl implements BasicDao {

private Class currentClass;

private SessionFactory sessionFactory;

public SessionFactory getSessionFactory() {
    return sessionFactory;
}

public void setSessionFactory(SessionFactory sessionFactory) {
    this.sessionFactory = sessionFactory;
}

@Transactional(readOnly = true)
@Override
public T getById(long id) {
    Session session = getCurrentSession();
    return (T) session.get(getGenericClass(), id);
}

@Transactional(readOnly = true)
@Override
public List<T> getAll() {
    Session session = getCurrentSession();
    return session.createCriteria(getGenericClass()).list();
}

@Transactional(readOnly = false)
@Override
public void create(T entity) {
    Session session = getCurrentSession();
    session.save(entity);
}

@Transactional(readOnly = false)
@Override
public void update(T entity) {
    getCurrentSession().update(entity);
}

@Transactional(readOnly = false)
@Override
public void delete(T entity) {
    Session session = getCurrentSession();
    session.delete(entity);
}

@Override
@Transactional(readOnly = false)
public void update(Collection<T> entities) {
    Session session = getCurrentSession();
    for (T entity : entities) {
        session.update(entity);
    }
}

@Override
@Transactional(readOnly = false)
public void create(List<T> entities) {
    Session session = getCurrentSession();
    for (T entity : entities) {
        session.save(entity);
    }
}

private Class getGenericClass() {
    if (currentClass == null) {
        ParameterizedType type = (ParameterizedType) getClass().getGenericSuperclass();
        currentClass = (Class) type.getActualTypeArguments()[0];
    }
    return currentClass;
}

protected Session getCurrentSession() {
    return sessionFactory.getCurrentSession();
}
}

(SessionFactory is injected)

I know it’s not configured for single session (like using update instead of merge), but first I want to get rid of LazyInitializationException.

What I can see from the debugging that sessionFactory.getCurrentSession() on each request returns session with a different hashCode

Now what have I done wrong?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T08:32:32+00:00Added an answer on June 17, 2026 at 8:32 am

    Starting from Hibernate 4.1.7 you can turn off transactions on lazy associations as a config property. more details

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a spring application that has configured log4j (via xml) and that runs
Need some help solving the following issue. I have web-application in Java, with Spring
I have a spring bean that I have configured in applicationContext like below: <bean
I have an issue using Ajax upload with Spring 3 MVC. I understand that
I am noticing a strange issue with respect to spring XML schemas. I have
I have a Spring web app with an applicationContext.xml and a dispatcher-servlet.xml configuration. I've
I have a web application in Spring that has a functional requirement for generating
I have a Spring application-context.xml with PropertyPlaceholderConfigurer to get properties' values from .properties file.
I have a strange issue that I am asked to make a Spring MVC
So very peculiar spring httpinvoker issue going on. I have a soap web service

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.