Uploaded image for project: 'Hibernate ORM'
  1. Hibernate ORM
  2. HHH-2643

Improve Session.refresh() Javdoc to clarify contract

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 5.2.5, 5.1.5
    • Component/s: documentation
    • Labels:
      None
    • Last commented by a user?:
      true

      Description

      It is tempting to use refresh() as an "undo" method when it was not designed as such. The manual is clear about how refresh() should be used, but doesn't mention how it should NOT be used. Refresh will not work on the following case:

      Cat cat = s.get(Cat.class, new Long(1l));
      cat.getKittens.add(new Cat());
      s.refresh(cat);
      

      It results in this:

      2012 ERROR org.hibernate.AssertionFailure  - an assertion failure occured (this may indicate a bug in Hibernate, but is more likely due to unsafe use of the session)
      org.hibernate.AssertionFailure: null identifier
      	at org.hibernate.engine.EntityKey.<init>(EntityKey.java:39)
      	at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:74)
      

      The presence of cascade type REFRESH makes it sound like this should work. The documentation needs to be more specific about not using refresh() as an undo facility. Hibernate itself is not a transaction handler.

        Attachments

          Issue links

            Activity

              People

              • Votes:
                1 Vote for this issue
                Watchers:
                4 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: