Announcement Announcement Module
No announcement yet.
Best practises for using Hibernate? Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Best practises for using Hibernate?


    I have some trouble with using hibernate and OpenSessionInViewFilter.
    I use the filter and it works.
    When I want to use a object longer than one request I move this object with Session.lock into the current session.
    For most of the time it works.
    But sometimes I get errors like:
    object is already assigned to this session
    object is opened in another session.

    Have anyone ideas for best practises using the hibernate framework and lazyloading?


  • #2
    Have you checked out the merge method? It may be of use.


    • #3
      Yes, I use the merge method in my method. And it works fine.
      But merge will save the object....


      • #4
        But merge will save the object....
        but why is that a problem? The main advantage of merge is that it does not associate the entity with the hibernate session. Take a look at Spring petclinic sample - it features merge inside the daos as well as a listener for transfering the id for new objects.


        • #5
          I don't want to save that object at this time in the workflow.
          e.g. I want to make a copy from the object graph and let modify the user the objects in the next request.
          You see I can not save the objects at this time...