Announcement Announcement Module
Collapse
No announcement yet.
Alternative to OpenSessionInViewFilter for non-webapps Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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?

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment


          • #6
            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.

            Comment

            Working...
            X