Results 1 to 6 of 6

Thread: Alternative to OpenSessionInViewFilter for non-webapps

  1. #1
    Join Date
    Oct 2006
    Posts
    20

    Default Alternative to OpenSessionInViewFilter for non-webapps

    I was wondering if there is an alternative for the OpenSessionInViewFilter for non-webapps? I am using Hibernate and all of my DAO's extend HibernateDAO support. I need to have lazy loading capabilities, and I was wondering if there is anything that I can use to start a hibernate session at the beginning of a particular method (at the service layer) and close it at the end of the method. I want to make sure that whatever I use will be transparent to my DAO's.

    I know that I can use the following code that I use in my Junit test cases, but I would prefer to leverage existing soutions if possible.

    Session session = getSessionFactory().openSession();
    TransactionSynchronizationManager.bindResource(get SessionFactory(), new SessionHolder(session));

    Thanks,
    jp4

  2. #2
    Join Date
    Oct 2004
    Location
    Herndon, VA, US
    Posts
    648

    Default

    If you just need this around the service layer methods, why not wrap these methods with transactions, which will automatically take care of the session for you?
    --Jing Xue

  3. #3
    Join Date
    Oct 2006
    Posts
    20

    Default

    I don't know why I didn't think of that. I use TransactionProxyFactoryBean on all of my DAO's, so all I have to do is configure the service the same exact way.

    Thanks, I'll give it a try.

    jp4

  4. #4
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    If you are going to make the services transactional, you don't have to repeat it on the dao. Obviously unless you really need it.

  5. #5
    Join Date
    Oct 2006
    Posts
    20

    Default

    I have everything setup to join an existing transaction. At this point, I don't know if the DAO's will be used outside of the service.

    thanks,

    jp4

  6. #6
    Join Date
    Sep 2006
    Location
    UK
    Posts
    8,424

    Default

    Quote Originally Posted by jp4 View Post
    I have everything setup to join an existing transaction. At this point, I don't know if the DAO's will be used outside of the service.
    , well if you find they are in the future, there's a little bit of tidying up you can do.

Posting Permissions

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