Announcement Announcement Module
Collapse
No announcement yet.
Single Session variable across prototype bean instances Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Single Session variable across prototype bean instances

    Hi,

    I have defined a Static org.hibernate.Session variable in my Bean class.

    Code:
     Class A {
    
      private static Session session;
    
      private SessionFactory sessionFactory;
    
      private void setSession(){
        if (session == null || !session.isOpen()) {
    	session = this.sessionFactory.openSession();
    
         }
      }
    
    
      public void setSessionFactory (){
     
            this.sessionFactory = sessionFactory;
    
     }
    
      .
      .
      .
      .
     }

    I have a method 'readData' inside this Class, which uses this session to read data from DB

    Code:
       public List readData(){
    
            setSession();
    
            //Logic to read data using HIbernate Criteria created using static session object;
            return data;
    
        }
    Class A is configured as a prototype bean in Spring config. Suppose i have 100 prorotype beans instantiated at the same time giving requests to readData() ; will there be any problem due to my above approach.

    my purpose is to share a single session object across all prototype beans of this class.

    Thanks and Regards,

    Pravin
Working...
X