List of usage examples for org.hibernate.collection.spi PersistentCollection clearDirty
void clearDirty();
From source file:org.granite.hibernate4.jmf.AbstractPersistentCollectionCodec.java
License:Open Source License
@SuppressWarnings("unchecked") public void decode(ExtendedObjectInput in, Object v) throws IOException, ClassNotFoundException, IllegalAccessException { PersistentCollection collection = (PersistentCollection) v; if (collection.wasInitialized()) { boolean sorted = (collection instanceof SortedSet || collection instanceof SortedMap); PersistentCollectionSnapshot snapshot = new JMFPersistentCollectionSnapshot(sorted, null); snapshot.readCoreData(in);//from w w w . j av a 2 s .c om if (collection instanceof Map) ((Map<Object, Object>) collection).putAll(snapshot.getElementsAsMap()); else ((Collection<Object>) collection).addAll(snapshot.getElementsAsCollection()); if (snapshot.isDirty()) collection.dirty(); else collection.clearDirty(); } }
From source file:org.jspresso.framework.application.backend.persistence.hibernate.HibernateHelper.java
License:Open Source License
/** * Whenever the entity has dirty persistent collection, make them clean to * workaround a "bug" with hibernate since hibernate cannot re-attach a * "dirty" detached collection./*w ww .ja v a 2s.co m*/ * * @param collection the collection * @param targetSession the session that is targeted to after the dirty states have been * reset or null if none. */ public static void unsetCollectionHibernateSession(PersistentCollection collection, Session targetSession) { // Whenever the entity has dirty persistent collection, make them // clean to workaround a "bug" with hibernate since hibernate cannot // re-attach a "dirty" detached collection. if (collection != null) { if (Hibernate.isInitialized(collection)) { collection.clearDirty(); } if (collection instanceof AbstractPersistentCollection && ((AbstractPersistentCollection) collection).getSession() != null && targetSession != ((AbstractPersistentCollection) collection).getSession()) { // The following is to avoid to avoid Hibernate exceptions due to // re-associating a collection that is already associated with the // session. collection.unsetSession(((AbstractPersistentCollection) collection).getSession()); } } }