Improve Session.refresh() Javdoc to clarify contract

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:

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

It results in this:

1 2 3 4 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.

Environment

None

Status

Assignee

Vlad Mihalcea

Reporter

Chris Bredesen

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Priority

Minor