Results 1 to 3 of 3

Thread: Lazy Loading Objects

  1. #1
    Join Date
    Aug 2004
    Location
    Whitehorse, YT, Canada
    Posts
    26

    Default Lazy Loading Objects

    I am writing an application that will be using Spring-RCP for the user front-end, but not for the cron'd processes at night on the server. I have read many articles on Spring, DAOs, and lazy-loading, but the true answer seems to evade me.

    I have my setup wired with a data source to HSQLDB (moving to Oracle once more of the application has been developed), LocalSessionFactoryBean to Hibernate, HibernateInterceptor, HibernateTransactionManager, TransactionInterceptor, and a ProxyFactoryBean.

    In the DAO, I'm obtaining my own Session object from the SessionFactoryUtils class for each method which needs to read/write to the session.

    In my Junit tests, I have a setUp and tearDown which opens and closes the Hibernate session as per an article I read on Karl Baum's blog. The tests work great with the lazy loading.

    If this were a web application, I could just use the OpenSessionInView(Interceptor/Filter), but that still doesn't help with my server processes which wouldn't run in the servlet context nor through a SimpleUrlHandlerMapper.

    So with my two requirements, Spring-RCP and cron'd server processes, what is the best way to wrap a session around my processes? I have looked at AOP, but I have no idea how that is wrapped around a method call.

    Any tips or direction would be greatly appreciated.

    Thank you,
    smv

  2. #2
    Join Date
    Nov 2004
    Posts
    18

    Default

    I have the same doubt than you.

    I don't know how to mantain the same session during a unit of work. It has to get the session on a service method (where start the transaction) and use it during the execution of this method. Daos and other services called by this has to use the same Session.

    Any ideas.

    Thanks.

  3. #3
    Join Date
    Aug 2004
    Posts
    229

    Default

    Let's clarify your architecture a little. You say, "conr'd processes at night on the server". This seems to indicate that you have some server process that runs at night - and it looks like this server process is written in Java + Spring? On the client side you have a Spring rich client based UI. So, what does this UI use to access data? Does it communicate with a middle tier via RPC or web services? Or does it directly connect to the DB? In other words, where are the DAOs located, in the client process or in some server process? I'm guessing that any "server process" wouldn't be the same thing as the "cron'd processes" since cron'd processes typically aren't running 24/7, making them unavailable as service providers to a rich client.
    But I can at least clarify a little how Spring interacts with Hibernate. Basically, Spring associates Hibernate Sessions to transactions on a per-thread basis. In other words, if you want to retrieve the same Hibernate Session from SessionFactoryUtils across several method calls you have to do two things: 1) ensure the calls happen in the same thread, and 2) perform them in the same transaction. So, probably whats missing from your setup is a proxy that surrounds your "unit" with a Spring managed transaction. Once your architecture is clarified we can figure out exactly what "unit" means. I should note that if "unit" = a long lasting user interaction session then you probably won't be able to surround it with a transaction and will have to approach the problem from a different angle.

    - Andy

Similar Threads

  1. Replies: 2
    Last Post: Dec 8th, 2005, 09:00 AM
  2. how to use hibernate lazy loading with spring transaction
    By tanmoy.chakraborty in forum Data
    Replies: 1
    Last Post: Oct 11th, 2005, 02:07 AM
  3. Hibernate and Lazy Loading.
    By cmrudd in forum Data
    Replies: 1
    Last Post: Oct 3rd, 2005, 03:58 AM
  4. Table list on page and lazy loading
    By lovkiys in forum Architecture
    Replies: 0
    Last Post: Aug 26th, 2005, 11:04 AM
  5. Replies: 4
    Last Post: Jun 20th, 2005, 10:52 AM

Posting Permissions

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