Hibernate version: 3.1.2
Mapping:
I've got class 'MainClass' with collection 'items' with cascade ALL
@OneToMany(cascade={CascadeType.ALL)
@Cascade( org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@JoinColumn(name="SOME_NAME")
@Sort(type=SortType.COMPARATOR, comparator=MyComparator.class)
private SortedSet<Item> items;
Code between sessionFactory.openSession() and session.close():
// finding mainClass
MainClass mainClass = EntityManager.find(...);
//some actions to initialize collection
mainClass.getItems()
....
//clearing collection and adding new items
mainClass.getItems().clear();
//adding some new items to collection
mainClass.getItems().add(new Item());
...
//need to rollback changes
EntityManager.refresh(mainClass); // exception here occurs
Full stack trace of any exception that occurs:
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:33)
at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:74)
at org.hibernate.impl.SessionImpl.fireRefresh(SessionImpl.java:835)
at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:829)
at org.hibernate.engine.CascadingAction$4.cascade(CascadingAction.java:92)
at org.hibernate.engine.Cascade.cascadeToOne(Cascade.java:213)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:157)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascadeCollectionElements(Cascade.java:290)
at org.hibernate.engine.Cascade.cascadeCollection(Cascade.java:185)
at org.hibernate.engine.Cascade.cascadeAssociation(Cascade.java:160)
at org.hibernate.engine.Cascade.cascadeProperty(Cascade.java:108)
at org.hibernate.engine.Cascade.cascade(Cascade.java:248)
at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:99)
at org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:39)
at org.hibernate.impl.SessionImpl.fireRefresh(SessionImpl.java:824)
Solution:
When I remove cascade refresh, no exception.
@OneToMany(cascade={CascadeType.PERSIST,CascadeType.MERGE, CascadeType.REMOVE})
|