Announcement Announcement Module
No announcement yet.
Hibernate updating a non-dirty persistent object Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate updating a non-dirty persistent object

    Hello everyone, we've run into a interesting issue with using SWF. I'll do my best to explain the situation from what I understand is going on.

    We have a basic form to save an entity. The create method used to persist the entity is annotated with @Transactional, and saving entities is not a problem. We are using the basic getSession().save(..).

    Now, we are trying to incorporate this basic form into a flow. We have defined a view-state, setting the view attribute to this basic form. The idea is to transition to this basic form, create an entity, then transition back (this could be done multiple times). This all works fine. The issue we are experiencing is that Hibernate is executing an SQL update statement each time a new entity is created using this basic form in the context of the flow. For some reason, this update statement will set 2 properties to null on all previously created entities during this flow session. The update statement is not executed for the first entity created for the flow session. It's only done if there are 1 or more entities that have been created during the current flow.

    If the basic form is used outside the flow context, Hibernate does not execute any update statement.

    We are using the persistence context element within the flow. I'm assuming it has something to do with that. I'm not sure where to look at this point. Any ideas?


  • #2
    Ok, I've found the solution referencing this thread: for anyone that may read this in the future.

    In our situation, the entity inherited from a super class and was annotated with @MappedSuperclass. This super class did not implement Serializable. It seems that since it did not implement Serializable the fields were set to null and somehow Hibernate updated these fields when they were changed.

    I guess I don't entirely understand how these entities stayed within the persistent context of the flow. But by implementing Serializable it solved the problem.

    If anyone can expand on this feel free to reply. I would be interested in knowing why this solution works.