Announcement Announcement Module
Collapse
No announcement yet.
Session scope with DAOs Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

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

    Comment


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

      Comment

      Working...
      X