Results 1 to 3 of 3

Thread: Session scope with DAOs

  1. #1

    Default Session scope with DAOs

    As far as I understand it, when using Hibernate DAOs, the scope of the session is limited to the actual method on the DAO. In order to do lazy loading against the returned object, you have to use the OpenSessionInView.

    So, on our app, we're using that. If I pass in a detached object from the front end, and re-load it (using its ID), I can navigate the object graph in the service layer.

    For some reason, though, if I save that object first, then try to navigate the graph in the service layer, I get a lazy-load exception. For that matter, if I save the object, then try to re-load it, I get the same exception.

    How should I go about trying to save an object from the front-end, and then needing to navigate its graph to make relationship changes, all in the service layer?

    jason

  2. #2
    Join Date
    Aug 2004
    Location
    Melbourne, Australia
    Posts
    1,104

    Default

    As far as I understand it, when using Hibernate DAOs, the scope of the session is limited to the actual method on the DAO
    A Session can have transaction scope across many DAOs. If any existing corresponding Session is bound to the current thread, it will be re-used.

    In order to do lazy loading against the returned object, you have to use the OpenSessionInView
    Yes (if by "returned object" you mean that returned by the transactional service layer).

    if I save that object first, then try to navigate the graph in the service layer, I get a lazy-load exception
    So you're saving in the service layer, and getting the lazy-load exception in the service layer? This is strange.

    How should I go about trying to save an object from the front-end...?
    Can you post the code, relevant application context and stack trace?

  3. #3

    Default

    Realized what the problem was. When I pass the object out, I init its collection, because I need to render the web page with that data.

    When it comes back, it still has that collection initialized. I save the main object, but that does not reattach the objects in the collection, so if I try to navigate their relationships, they throw exception.

    I haven't decided how to solve the problem, but I suspect I can make a DAO call to reinit that collection, or do a save cascade to reattach the collection parts.

Similar Threads

  1. OpenSessionInView and portlet support
    By garpinc2 in forum Web Flow
    Replies: 31
    Last Post: Apr 9th, 2010, 11:12 AM
  2. Loosing my SecureContext
    By sklakken in forum Security
    Replies: 3
    Last Post: Jul 21st, 2005, 01:44 PM
  3. Replies: 3
    Last Post: May 16th, 2005, 07:04 AM
  4. Replies: 1
    Last Post: Mar 12th, 2005, 04:33 AM
  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
  •