use of org.hibernate.action.internal.DelayedPostInsertIdentifier in project hibernate-orm by hibernate.
the class Collections method prepareCollectionForUpdate.
/**
* 1. record the collection role that this collection is referenced by
* 2. decide if the collection needs deleting/creating/updating (but
* don't actually schedule the action yet)
*/
private static void prepareCollectionForUpdate(PersistentCollection<?> collection, CollectionEntry entry, SessionFactoryImplementor factory) {
if (entry.isProcessed()) {
throw new AssertionFailure("collection was processed twice by flush()");
}
entry.setProcessed(true);
final CollectionPersister loadedPersister = entry.getLoadedPersister();
final CollectionPersister currentPersister = entry.getCurrentPersister();
if (loadedPersister != null || currentPersister != null) {
// it is or was referenced _somewhere_
// check if the key changed
// excludes marking key changed when the loaded key is a DelayedPostInsertIdentifier.
final boolean keyChanged = currentPersister != null && entry != null && !currentPersister.getKeyType().isEqual(entry.getLoadedKey(), entry.getCurrentKey(), factory) && !(entry.getLoadedKey() instanceof DelayedPostInsertIdentifier);
// if either its role changed, or its key changed
final boolean ownerChanged = loadedPersister != currentPersister || keyChanged;
if (ownerChanged) {
// do a check
final boolean orphanDeleteAndRoleChanged = loadedPersister != null && currentPersister != null && loadedPersister.hasOrphanDelete();
if (orphanDeleteAndRoleChanged) {
throw new HibernateException("Don't change the reference to a collection with delete-orphan enabled : " + loadedPersister.getRole());
}
// do the work
if (currentPersister != null) {
entry.setDorecreate(true);
}
if (loadedPersister != null) {
// we will need to remove the old entries
entry.setDoremove(true);
if (entry.isDorecreate()) {
LOG.trace("Forcing collection initialization");
collection.forceInitialization();
}
}
} else if (collection.isDirty()) {
// the collection's elements have changed
entry.setDoupdate(true);
}
}
}
use of org.hibernate.action.internal.DelayedPostInsertIdentifier in project hibernate-orm by hibernate.
the class DefaultLoadEventListener method onLoad.
/**
* Handle the given load event.
*
* @param event The load event to be handled.
*/
public void onLoad(final LoadEvent event, final LoadType loadType) throws HibernateException {
final EntityPersister persister = getPersister(event);
if (persister == null) {
throw new HibernateException("Unable to locate persister: " + event.getEntityClassName());
}
if (!persister.getIdentifierMapping().getJavaType().isInstance(event.getEntityId()) && !(event.getEntityId() instanceof DelayedPostInsertIdentifier)) {
checkIdClass(persister, event, loadType, persister.getIdentifierType().getReturnedClass());
}
doOnLoad(persister, event, loadType);
}
Aggregations