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

  • Problems with merging

    I am using Roo 1.0.2.

    If I call merge() on an entity twice (for instance pressing save button twice in gui) I get a

    org.springframework.orm.jpa.JpaOptimisticLockingFa ilureException: org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction

    The entity has not changed or been updated by another.

    If I try to simulate it in a test:

    Code:
       	Person p = new Person();
        	p.setUniqueField("0000000000");
        	p.merge();
        	p.merge();
    I get

    org.springframework.dao.DataIntegrityViolationExce ption: org.hibernate.exception.ConstraintViolationExcepti on: could not insert: [Person]; nested exception is javax.persistence.EntityExistsException: org.hibernate.exception.ConstraintViolationExcepti on: could not insert: [Person]

    So I try another simulation

    Code:
        1	Person p = new Person();
        2	p.setUniqueField("0");
        3	p.merge();
        4	p = p.findPerson(p.getId());
        5	p.merge();
        6	p.merge();
        7	p.merge();
        9	p.setCityName("ZZZ");
       10	p.merge();
    The I get the JpaOptimisticLockingFailureException but not until line 10.

    Can anybody explain to me what is going on here and how to fix this?

    Regards
    Christian
    Last edited by christian@landbo.net; Jul 29th, 2010, 02:29 PM. Reason: Better title

  • #2
    Problem solved.

    Please ignore the unit tests - the problem was something else.

    It was due to this:

    Oracle converts empty string to null but JPA doesn’t update entity cache correspondingly (http://stackoverflow.com/questions/6...cache-correspo)

    /Chr

    Comment


    • #3
      I seem to be running into the same problem when a user edits an entity including an empty string field, saves the edit form and then goes back (browser back function) to the form and tries to save again. It only happens when using Oracle 11g and not with MySQL.

      How did you solve it?

      Comment


      • #4
        Originally posted by Harald Walker View Post
        I seem to be running into the same problem when a user edits an entity including an empty string field, saves the edit form and then goes back (browser back function) to the form and tries to save again. It only happens when using Oracle 11g and not with MySQL.
        In my case it was a combination of two issues. Because of how Oracle handles empty strings, the version number of the entity got increased each time (even if there was no change) and if a user uses the back button of the browser, the previous version number was still in the browser cache and this caused the exception. Disabling browser cache for update pages solves that, but then the version number still gets increased, which can be prevented by settings empty string fields to null before merging.

        Comment

        Working...
        X