Announcement Announcement Module
Collapse
No announcement yet.
Form model and hibernate object id Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Form model and hibernate object id

    Hi, I am using spring, struts and hibernate.

    This is the situation:

    I've got a ActionsForm (let's call it form) and a property of it is an object called Software.

    Software happens to be a hibernate object.

    In the html form we have a drop down list of software the user can select. The values in the list are software Ids. When the user selects a new software the current software attached to the form object has it's softwareId updated by struts.

    We later load a new software using hibernate from the db and pass it to form.setSoftware();

    The database relationship is many forms to a software object

    The problem is that this is causing an occational error:

    org.springframework.orm.hibernate.HibernateSystemE xception: identifier of an
    instance of Software altered from MSIIS5 to MSIIS6

    The only solution I can think of is to ensure that when form.setSoftware() if passed a software object it makes a copy of the object (which is not associated with a session). Then when we save the user's software selection we will have to load another software from the db and associate it with the form before saving the form.

    This is really messy. How have others solved this problem.

    Some help would be much appreciated before I hack our system.

    Thanks

  • #2
    Ok, so now that I have had some sleep...

    The neatest solution I can think of is...

    add a softwareId field to form. change the name of the dropdown list to set it's value, then in the action. use the form.softwareId to load a software (hibernate) object and pass that to form.setSofware().

    As I said the error occurs infrequently. hibernate must call flush occationaly. because the following will cause the error.

    software = session.load(Software.class)
    software.setId("")


    session.flush() // error occurs

    Comment

    Working...
    X