Announcement Announcement Module
Collapse
No announcement yet.
Several Hibernate Exceptions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • #16
    I use the ID for other purposes.
    I gave the wrong example, because my problem is with update and not with save.

    my upate method is this:

    Code:
    public void updateAccount(Account account){
        getHibernateTemplate().update(account);
    }
    Here I get the NonUniqueObjectException. But, if I change this to use merge instead of udpate it works fine.
    My question is why other DAO works fine with update.
    There is nothing special in my Account class.

    Comment


    • #17
      Otherwise he would not even be able to compile his code.
      yes, i know, but maybe he tried this

      Code:
      public Long saveAccount(Account account){
          return (Long) getHibernateTemplate().save(account);
      }
      by
      public void saveAccount(Account account){
          getHibernateTemplate().update(account);
      }
      I gave the wrong example, because my problem is with update and not with save
      ohhh

      But, if I change this to use merge instead of udpate it works fine.
      i never work with merge, have you tried with saveOrUpdate???

      My question is why other DAO works fine with update.
      likei said, pls share your sequence of interaction, maybe you have 2 objects with the same id open and when you try to update one of them, you recieve the Exception

      regards

      Comment


      • #18
        saveOrUpdate() it's called by the save method of HibernateTemplate. Take a look at the stack trace that I've posted at the first page.

        merge() doesn't reattach the object to the session (that is what I read).

        I'm using Tapestry and the object is setted by the @Insert component that uses OGNL.

        Comment


        • #19
          Originally posted by mateamargo View Post
          merge() doesn't reattach the object to the session (that is what I read).
          The documentation about merge() confused me as well. The secret is that it does indeed not attach the object passed as parameter to it to the session. BUT it returns the object that is actually/already attached to the session. So usually code with merge() looks probably like:

          Code:
          Object entity = // where ever we got it from;
          entity = merge(entity);
          The reason for the failure of the other methods is that an object of the same id is already attached to the session. By calling one of those methods you actually try to attach it again and get some kind of a conflict. But IMO Hibernate should really hide these details from a user. I can't see any advantage of messing with all those minor differences of the methods.

          Joerg

          Comment

          Working...
          X