Results 1 to 7 of 7

Thread: Session Management in Spring?

  1. #1
    Join Date
    Nov 2004
    Posts
    159

    Default 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. #2
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    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.

  3. #3
    Join Date
    Nov 2004
    Posts
    159

    Default

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

  4. #4
    Join Date
    Aug 2004
    Location
    Sydney, Australia
    Posts
    2,768

    Default

    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.

  5. #5
    Join Date
    Nov 2004
    Posts
    159

    Default

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

    Thanks Ben.

  6. #6
    Join Date
    Oct 2004
    Location
    Antwerp, Belgium
    Posts
    96

    Default

    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?

  7. #7
    Join Date
    Nov 2004
    Posts
    159

    Default

    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.


Similar Threads

  1. Replies: 0
    Last Post: Aug 25th, 2005, 05:11 AM
  2. Replies: 1
    Last Post: Mar 12th, 2005, 04:33 AM
  3. Replies: 14
    Last Post: Feb 21st, 2005, 05:41 PM
  4. Session Management in Spring?
    By spring04 in forum Web
    Replies: 3
    Last Post: Dec 6th, 2004, 02:48 PM
  5. Replies: 3
    Last Post: Nov 19th, 2004, 07:16 PM

Posting Permissions

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