Announcement Announcement Module
Collapse
No announcement yet.
Session Management in Spring? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session Management in Spring?

    Is it possible that i can choose NOT to use the automatic session management provided by spring and do it myself in my spring application. For example, i've a DAO object testDAO and i've provided hibernate implementation for this as follows.

    HibernateTestDAO extends HibernateDaoSupport implements testDAO


    In this class, in my implementation, say for methodA, can i do as below:

    Code:
    public void methodA() throws DataAccessException {
       SessionFactory s = getHibernateTemplate().getSessionFactory();
    
       Session s1 = s.openSession();
    
       // CREATE QUERY
      // execute query
      // close session
    }
    If it's possible, do i need to manage the transaction as well?

    I'm sorry if i'm asking some weird question.

    Thoughts?

    Thanks!

  • #2
    CanI just ask why would you want to do that? The overall approach just doesn't feel right - handling things Spring already does.

    Also, you'd get more support from the data access experts like Colin over the in the Data Access forum.

    Comment


    • #3
      Thanks Ben. I don't have any example as such but does sprin provide such flexibility?

      Comment


      • #4
        I don't know but I can't imagine why there would be a good reason. I have accessed the Hibernate Session Factory in order to obtain a data source from it on occasion, but I don't know why you'd want to ignore the HibernateTemplate model which catches all your exceptions nicely.

        Comment


        • #5
          As i said, i've not found any example for this. I just wanted to know if this is possible.

          Thanks Ben.

          Comment


          • #6
            Why to you need to create your own sessions? Spring offers a rich set of tools to configure transactions declaritively. Your Hibernate beans will be detached from the second session and persistent in the one inside HibernateTemplate (if you use that one). Yet you are connecting to the database through the same datasource. Does this make sense to you?

            Comment


            • #7
              May for debugging purposes. As i said before, i didn't have anything specific in mind.

              May be it doesn't make sense to create session on my own inside spring.

              Comment

              Working...
              X