HHH-18552 clean up inappropriate usages of TransientObjectException
and minor cleanups in StatefulPersistenceContext Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
parent
7422c18a94
commit
f45e3db4b0
|
@ -373,10 +373,9 @@ public final class ForeignKeys {
|
|||
|
||||
private static void throwIfTransient(String entityName, Object object, SharedSessionContractImplementor session) {
|
||||
if ( isTransient( entityName, object, Boolean.FALSE, session ) ) {
|
||||
throw new TransientObjectException(
|
||||
"object references an unsaved transient instance - save the transient instance before flushing: " +
|
||||
(entityName == null ? session.guessEntityName(object) : entityName)
|
||||
);
|
||||
throw new TransientObjectException( "Entity references an unsaved transient instance of '"
|
||||
+ (entityName == null ? session.guessEntityName(object) : entityName)
|
||||
+ "' (make the transient instance persistent before flushing)" );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -33,7 +33,6 @@ import org.hibernate.LockMode;
|
|||
import org.hibernate.MappingException;
|
||||
import org.hibernate.NonUniqueObjectException;
|
||||
import org.hibernate.PersistentObjectException;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
|
||||
import org.hibernate.bytecode.enhance.spi.interceptor.EnhancementAsProxyLazinessInterceptor;
|
||||
import org.hibernate.collection.spi.PersistentCollection;
|
||||
|
@ -79,6 +78,7 @@ import static org.hibernate.engine.internal.ManagedTypeHelper.asHibernateProxy;
|
|||
import static org.hibernate.engine.internal.ManagedTypeHelper.asManagedEntity;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.asPersistentAttributeInterceptable;
|
||||
import static org.hibernate.engine.internal.ManagedTypeHelper.isPersistentAttributeInterceptable;
|
||||
import static org.hibernate.proxy.HibernateProxy.extractLazyInitializer;
|
||||
|
||||
/**
|
||||
* A <em>stateful</em> implementation of the {@link PersistenceContext} contract, meaning that we maintain this
|
||||
|
@ -217,7 +217,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
//
|
||||
@Override
|
||||
public PersistentCollection<?> useUnownedCollection(CollectionKey key) {
|
||||
return ( unownedCollections == null ) ? null : unownedCollections.remove( key );
|
||||
return unownedCollections == null ? null : unownedCollections.remove( key );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -234,7 +234,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
//Strictly avoid lambdas in this case
|
||||
for ( EntityHolderImpl value : entitiesByKey.values() ) {
|
||||
if ( value != null && value.proxy != null ) {
|
||||
HibernateProxy.extractLazyInitializer( value.proxy ).unsetSession();
|
||||
extractLazyInitializer( value.proxy ).unsetSession();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -337,9 +337,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
if ( cachedValue != null ) {
|
||||
return cachedValue;
|
||||
}
|
||||
|
||||
// check to see if the natural id is mutable/immutable
|
||||
if ( persister.getEntityMetamodel().hasImmutableNaturalId() ) {
|
||||
else if ( persister.getEntityMetamodel().hasImmutableNaturalId() ) {
|
||||
// an immutable natural-id is not retrieved during a normal database-snapshot operation...
|
||||
final Object naturalIdFromDb = persister.getNaturalIdentifierSnapshot( id, session );
|
||||
naturalIdResolutions.cacheResolutionFromLoad( id, naturalIdFromDb, persister );
|
||||
|
@ -353,7 +352,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
if ( entitySnapshot == NO_ROW || entitySnapshot == null ) {
|
||||
return null;
|
||||
}
|
||||
|
||||
else {
|
||||
final Object[] naturalIdSnapshotSubSet = new Object[ props.length ];
|
||||
for ( int i = 0; i < props.length; i++ ) {
|
||||
naturalIdSnapshotSubSet[i] = entitySnapshot[ props[i] ];
|
||||
|
@ -362,6 +361,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
return naturalIdSnapshotSubSet;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private EntityPersister locateProperPersister(EntityPersister persister) {
|
||||
return persister.getRootEntityDescriptor().getEntityPersister();
|
||||
|
@ -429,9 +429,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
public void postLoad(JdbcValuesSourceProcessingState processingState, Consumer<EntityHolder> holderConsumer) {
|
||||
final Callback callback = processingState.getExecutionContext().getCallback();
|
||||
if ( processingState.getLoadingEntityHolders() != null ) {
|
||||
final EventListenerGroup<PostLoadEventListener> listenerGroup = getSession().getFactory()
|
||||
.getFastSessionServices()
|
||||
.eventListenerGroup_POST_LOAD;
|
||||
final EventListenerGroup<PostLoadEventListener> listenerGroup =
|
||||
getSession().getFactory().getFastSessionServices().eventListenerGroup_POST_LOAD;
|
||||
final PostLoadEvent postLoadEvent = processingState.getPostLoadEvent();
|
||||
for ( final EntityHolder holder : processingState.getLoadingEntityHolders() ) {
|
||||
processLoadedEntityHolder( holder, listenerGroup, postLoadEvent, callback, holderConsumer );
|
||||
|
@ -460,8 +459,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
// in which case we added an entry with a null proxy and entity.
|
||||
// Remove that empty entry on post load to avoid unwanted side effects
|
||||
entitiesByKey.remove( holder.getEntityKey() );
|
||||
return;
|
||||
}
|
||||
else {
|
||||
if ( postLoadEvent != null ) {
|
||||
postLoadEvent.reset();
|
||||
postLoadEvent.setEntity( holder.getEntity() )
|
||||
|
@ -481,6 +480,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
}
|
||||
( (EntityHolderImpl) holder ).entityInitializer = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEntity(EntityKey key, Object entity) {
|
||||
|
@ -498,7 +498,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
holder = oldHolder;
|
||||
}
|
||||
else {
|
||||
entityHolderMap.put( key, holder = EntityHolderImpl.forEntity( key, key.getPersister(), entity ) );
|
||||
holder = EntityHolderImpl.forEntity( key, key.getPersister(), entity );
|
||||
entityHolderMap.put( key, holder );
|
||||
}
|
||||
holder.state = EntityHolderState.INITIALIZED;
|
||||
final BatchFetchQueue fetchQueue = this.batchFetchQueue;
|
||||
|
@ -614,8 +615,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
final boolean existsInDatabase,
|
||||
final EntityPersister persister,
|
||||
final boolean disableVersionIncrement) {
|
||||
EntityHolder entityHolder = addEntityHolder( entityKey, entity );
|
||||
EntityEntry entityEntry = addEntry(
|
||||
final EntityHolder entityHolder = addEntityHolder( entityKey, entity );
|
||||
final EntityEntry entityEntry = addEntry(
|
||||
entity,
|
||||
status,
|
||||
loadedState,
|
||||
|
@ -731,7 +732,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
if ( ! Hibernate.isInitialized( value ) ) {
|
||||
|
||||
// could be a proxy....
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( value );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( value );
|
||||
if ( lazyInitializer != null ) {
|
||||
reassociateProxy( lazyInitializer, asHibernateProxy( value ) );
|
||||
return true;
|
||||
|
@ -740,7 +741,8 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
// or an uninitialized enhanced entity ("bytecode proxy")...
|
||||
if ( isPersistentAttributeInterceptable( value ) ) {
|
||||
final PersistentAttributeInterceptable bytecodeProxy = asPersistentAttributeInterceptable( value );
|
||||
final BytecodeLazyAttributeInterceptor interceptor = (BytecodeLazyAttributeInterceptor) bytecodeProxy.$$_hibernate_getInterceptor();
|
||||
final BytecodeLazyAttributeInterceptor interceptor =
|
||||
(BytecodeLazyAttributeInterceptor) bytecodeProxy.$$_hibernate_getInterceptor();
|
||||
if ( interceptor != null ) {
|
||||
interceptor.setSession( getSession() );
|
||||
}
|
||||
|
@ -754,7 +756,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
@Override
|
||||
public void reassociateProxy(Object value, Object id) throws MappingException {
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( value );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( value );
|
||||
if ( lazyInitializer != null ) {
|
||||
LOG.debugf( "Setting proxy identifier: %s", id );
|
||||
lazyInitializer.setIdentifier( id );
|
||||
|
@ -792,7 +794,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
@Override
|
||||
public Object unproxy(Object maybeProxy) throws HibernateException {
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( maybeProxy );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( maybeProxy );
|
||||
if ( lazyInitializer != null ) {
|
||||
if ( lazyInitializer.isUninitialized() ) {
|
||||
throw new PersistentObjectException(
|
||||
|
@ -809,7 +811,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
@Override
|
||||
public Object unproxyAndReassociate(final Object maybeProxy) throws HibernateException {
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( maybeProxy );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( maybeProxy );
|
||||
if ( lazyInitializer != null ) {
|
||||
reassociateProxy( lazyInitializer, asHibernateProxy( maybeProxy ) );
|
||||
//initialize + unwrap the object and return it
|
||||
|
@ -858,7 +860,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
// Similarly, if the original HibernateProxy is initialized, there
|
||||
// is again no point in creating a proxy. Just return the impl
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( proxy );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( proxy );
|
||||
if ( !lazyInitializer.isUninitialized() ) {
|
||||
final Object impl = lazyInitializer.getImplementation();
|
||||
// can we return it?
|
||||
|
@ -871,16 +873,13 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
|
||||
// Otherwise, create the narrowed proxy
|
||||
final HibernateProxy narrowedProxy = asHibernateProxy( persister.createProxy( key.getIdentifier(), session ) );
|
||||
|
||||
// set the read-only/modifiable mode in the new proxy to what it was in the original proxy
|
||||
final boolean readOnlyOrig = lazyInitializer.isReadOnly();
|
||||
narrowedProxy.getHibernateLazyInitializer().setReadOnly( readOnlyOrig );
|
||||
|
||||
narrowedProxy.getHibernateLazyInitializer().setReadOnly( lazyInitializer.isReadOnly() );
|
||||
return narrowedProxy;
|
||||
}
|
||||
else {
|
||||
if ( object != null ) {
|
||||
HibernateProxy.extractLazyInitializer( proxy ).setImplementation( object );
|
||||
extractLazyInitializer( proxy ).setImplementation( object );
|
||||
}
|
||||
return proxy;
|
||||
}
|
||||
|
@ -1531,7 +1530,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
if ( mergeMap != null ) {
|
||||
for ( Object o : mergeMap.entrySet() ) {
|
||||
final Entry<?,?> mergeMapEntry = (Entry<?,?>) o;
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( mergeMapEntry.getKey() );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( mergeMapEntry.getKey() );
|
||||
if ( lazyInitializer != null ) {
|
||||
if ( persister.isSubclassEntityName( lazyInitializer.getEntityName() ) ) {
|
||||
HibernateProxy proxy = asHibernateProxy( mergeMapEntry.getKey() );
|
||||
|
@ -1693,17 +1692,17 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
@Override
|
||||
public boolean isReadOnly(Object entityOrProxy) {
|
||||
if ( entityOrProxy == null ) {
|
||||
throw new AssertionFailure( "object must be non-null." );
|
||||
throw new IllegalArgumentException( "Null entity instance" );
|
||||
}
|
||||
boolean isReadOnly;
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( entityOrProxy );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( entityOrProxy );
|
||||
if ( lazyInitializer != null ) {
|
||||
isReadOnly = lazyInitializer.isReadOnly();
|
||||
}
|
||||
else {
|
||||
final EntityEntry ee = getEntry( entityOrProxy );
|
||||
if ( ee == null ) {
|
||||
throw new TransientObjectException( "Instance was not associated with this persistence context" );
|
||||
throw new IllegalArgumentException( "Instance is not associated with this persistence context" );
|
||||
}
|
||||
isReadOnly = ee.isReadOnly();
|
||||
}
|
||||
|
@ -1713,12 +1712,12 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
@Override
|
||||
public void setReadOnly(Object object, boolean readOnly) {
|
||||
if ( object == null ) {
|
||||
throw new AssertionFailure( "object must be non-null." );
|
||||
throw new IllegalArgumentException( "Null entity instance" );
|
||||
}
|
||||
if ( isReadOnly( object ) == readOnly ) {
|
||||
return;
|
||||
}
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( object );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( object );
|
||||
if ( lazyInitializer != null ) {
|
||||
setProxyReadOnly( lazyInitializer, readOnly );
|
||||
if ( ! lazyInitializer.isUninitialized() ) {
|
||||
|
@ -1733,7 +1732,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
// PersistenceContext.proxyFor( entity ) returns entity if there is no proxy for that entity
|
||||
// so need to check the return value to be sure it is really a proxy
|
||||
final Object maybeProxy = getSession().getPersistenceContextInternal().proxyFor( object );
|
||||
final LazyInitializer lazyInitializer1 = HibernateProxy.extractLazyInitializer( maybeProxy );
|
||||
final LazyInitializer lazyInitializer1 = extractLazyInitializer( maybeProxy );
|
||||
if ( lazyInitializer1 != null ) {
|
||||
setProxyReadOnly( lazyInitializer1, readOnly );
|
||||
}
|
||||
|
@ -1751,7 +1750,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
private void setEntityReadOnly(Object entity, boolean readOnly) {
|
||||
final EntityEntry entry = getEntry( entity );
|
||||
if ( entry == null ) {
|
||||
throw new TransientObjectException( "Instance was not associated with this persistence context" );
|
||||
throw new IllegalArgumentException( "Instance was not associated with this persistence context" );
|
||||
}
|
||||
entry.setReadOnly( readOnly, entity );
|
||||
hasNonReadOnlyEntities = hasNonReadOnlyEntities || ! readOnly;
|
||||
|
@ -1963,7 +1962,7 @@ public class StatefulPersistenceContext implements PersistenceContext {
|
|||
final EntityHolderImpl holder = EntityHolderImpl.forEntity( ek, persister, entity );
|
||||
holder.state = state;
|
||||
if ( proxy != null ) {
|
||||
final LazyInitializer lazyInitializer = HibernateProxy.extractLazyInitializer( proxy );
|
||||
final LazyInitializer lazyInitializer = extractLazyInitializer( proxy );
|
||||
if ( lazyInitializer != null ) {
|
||||
lazyInitializer.setSession( session );
|
||||
holder.proxy = proxy;
|
||||
|
|
|
@ -502,8 +502,8 @@ public class ActionQueue {
|
|||
final String path = transientEntities.getNonNullableTransientPropertyPaths(transientEntity).iterator().next();
|
||||
//TODO: should be TransientPropertyValueException
|
||||
throw new TransientObjectException( "Persistent instance of '" + insertAction.getEntityName()
|
||||
+ "' with id '" + insertAction.getId()
|
||||
+ "' references an unsaved transient instance via attribute '" + path
|
||||
+ "' with id [" + insertAction.getId()
|
||||
+ "] references an unsaved transient instance via attribute '" + path
|
||||
+ "' (save the transient instance before flushing)" );
|
||||
}
|
||||
|
||||
|
|
|
@ -339,7 +339,7 @@ public class CascadingActions {
|
|||
boolean isCascadeDeleteEnabled)
|
||||
throws HibernateException {
|
||||
if ( child != null && isChildTransient( session, child, entityName ) ) {
|
||||
throw new TransientObjectException( "persistent instance references an unsaved transient instance of '"
|
||||
throw new TransientObjectException( "Persistent instance references an unsaved transient instance of '"
|
||||
+ entityName + "' (save the transient instance before flushing)" );
|
||||
//TODO: should be TransientPropertyValueException
|
||||
// throw new TransientPropertyValueException(
|
||||
|
|
|
@ -179,7 +179,8 @@ public class DefaultDeleteEventListener implements DeleteEventListener, Callback
|
|||
|
||||
final Object id = persister.getIdentifier( entity, source );
|
||||
if ( id == null ) {
|
||||
throw new TransientObjectException("the detached instance passed to delete() had a null identifier");
|
||||
throw new TransientObjectException( "Cannot delete instance of entity '" + persister.getEntityName()
|
||||
+ "' because it has a null identifier" );
|
||||
}
|
||||
|
||||
final PersistenceContext persistenceContext = source.getPersistenceContextInternal();
|
||||
|
|
|
@ -71,8 +71,8 @@ public class DefaultLockEventListener extends AbstractLockUpgradeEventListener i
|
|||
final EntityPersister persister = source.getEntityPersister( event.getEntityName(), entity );
|
||||
final Object id = persister.getIdentifier( entity, source );
|
||||
if ( !ForeignKeys.isNotTransient( event.getEntityName(), entity, Boolean.FALSE, source ) ) {
|
||||
throw new TransientObjectException( "cannot lock an unsaved transient instance: "
|
||||
+ persister.getEntityName() );
|
||||
throw new TransientObjectException( "Cannot lock unsaved transient instance of entity '"
|
||||
+ persister.getEntityName() + "'" );
|
||||
}
|
||||
entry = reassociate( event, entity, id, persister );
|
||||
cascadeOnLock( event, persister, entity );
|
||||
|
|
|
@ -20,7 +20,6 @@ import org.hibernate.engine.internal.CascadePoint;
|
|||
import org.hibernate.engine.spi.ActionQueue;
|
||||
import org.hibernate.engine.spi.CascadingActions;
|
||||
import org.hibernate.engine.spi.EntityEntry;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
import org.hibernate.engine.spi.SessionFactoryImplementor;
|
||||
import org.hibernate.event.spi.EventSource;
|
||||
|
@ -132,7 +131,8 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
persister = source.getEntityPersister( event.getEntityName(), object );
|
||||
id = persister.getIdentifier( object, event.getSession() );
|
||||
if ( id == null ) {
|
||||
throw new TransientObjectException( "transient instance passed to refresh");
|
||||
throw new TransientObjectException( "Cannot refresh instance of entity '" + persister.getEntityName()
|
||||
+ "' because it has a null identifier" );
|
||||
}
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev(
|
||||
|
|
|
@ -77,7 +77,8 @@ public class DefaultReplicateEventListener
|
|||
// except null (that is, even ids which look like they're unsaved)
|
||||
final Object id = persister.getIdentifier( entity, source );
|
||||
if ( id == null ) {
|
||||
throw new TransientObjectException( "instance with null id passed to replicate()" );
|
||||
throw new TransientObjectException( "Cannot replicate instance of entity '" + persister.getEntityName()
|
||||
+ "' because it has a null identifier" );
|
||||
}
|
||||
|
||||
final Object oldVersion = replicationMode == ReplicationMode.EXCEPTION
|
||||
|
|
|
@ -572,7 +572,7 @@ public class SessionImpl
|
|||
|
||||
final EntityEntry e = persistenceContext.getEntry( object );
|
||||
if ( e == null ) {
|
||||
throw new TransientObjectException( "Given object not associated with the session" );
|
||||
throw new IllegalArgumentException( "Given entity is not associated with the persistence context" );
|
||||
}
|
||||
|
||||
if ( e.getStatus().isDeletedOrGone() ) {
|
||||
|
@ -1419,14 +1419,14 @@ public class SessionImpl
|
|||
final LazyInitializer lazyInitializer = extractLazyInitializer( object );
|
||||
if ( lazyInitializer != null ) {
|
||||
if ( lazyInitializer.getSession() != this ) {
|
||||
throw new TransientObjectException( "The proxy was not associated with this session" );
|
||||
throw new IllegalArgumentException( "Given proxy is not associated with the persistence context" );
|
||||
}
|
||||
return lazyInitializer.getInternalIdentifier();
|
||||
}
|
||||
else {
|
||||
final EntityEntry entry = persistenceContext.getEntry( object );
|
||||
if ( entry == null ) {
|
||||
throw new TransientObjectException( "The instance was not associated with this session" );
|
||||
throw new IllegalArgumentException( "Given entity is not associated with the persistence context" );
|
||||
}
|
||||
return entry.getId();
|
||||
}
|
||||
|
@ -1682,14 +1682,14 @@ public class SessionImpl
|
|||
final LazyInitializer lazyInitializer = extractLazyInitializer( object );
|
||||
if ( lazyInitializer != null ) {
|
||||
if ( !persistenceContext.containsProxy( object ) ) {
|
||||
throw new TransientObjectException( "proxy was not associated with the session" );
|
||||
throw new IllegalArgumentException( "Given proxy is not associated with the persistence context" );
|
||||
}
|
||||
object = lazyInitializer.getImplementation();
|
||||
}
|
||||
|
||||
final EntityEntry entry = persistenceContext.getEntry( object );
|
||||
if ( entry == null ) {
|
||||
throwTransientObjectException( object );
|
||||
throw new IllegalArgumentException( "Given entity is not associated with the persistence context" );
|
||||
}
|
||||
return entry.getPersister().getEntityName();
|
||||
}
|
||||
|
@ -1707,13 +1707,6 @@ public class SessionImpl
|
|||
}
|
||||
}
|
||||
|
||||
private void throwTransientObjectException(Object object) throws HibernateException {
|
||||
throw new TransientObjectException(
|
||||
"object references an unsaved transient instance - save the transient instance before flushing: " +
|
||||
guessEntityName( object )
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String guessEntityName(Object object) throws HibernateException {
|
||||
checkOpenOrWaitingForAutoClose();
|
||||
|
|
|
@ -101,10 +101,9 @@ public interface EntityIdentifierMapping extends ValuedModelPart {
|
|||
// deeper checks...
|
||||
final String entityName = findContainingEntityMapping().getEntityName();
|
||||
if ( ForeignKeys.isTransient( entityName, entity, Boolean.FALSE, session ) ) {
|
||||
throw new TransientObjectException(
|
||||
"object references an unsaved transient instance - save the transient instance before flushing: " +
|
||||
(entityName == null ? session.guessEntityName( entity ) : entityName)
|
||||
);
|
||||
throw new TransientObjectException( "object references an unsaved transient instance of '"
|
||||
+ (entityName == null ? session.guessEntityName( entity ) : entityName)
|
||||
+ "' save the transient instance before flushing" );
|
||||
}
|
||||
id = getIdentifier( entity );
|
||||
}
|
||||
|
|
|
@ -10,7 +10,6 @@ import org.hibernate.FlushMode;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LazyInitializationException;
|
||||
import org.hibernate.SessionException;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.boot.spi.SessionFactoryOptions;
|
||||
import org.hibernate.engine.spi.EntityKey;
|
||||
import org.hibernate.engine.spi.PersistenceContext;
|
||||
|
@ -372,7 +371,7 @@ public abstract class AbstractLazyInitializer implements LazyInitializer {
|
|||
|
||||
private void errorIfReadOnlySettingNotAvailable() {
|
||||
if ( session == null ) {
|
||||
throw new TransientObjectException(
|
||||
throw new IllegalStateException(
|
||||
"Proxy for [" + entityName + "#" + id + "] is not associated with a session"
|
||||
+ " (the read-only/modifiable setting is only accessible when the proxy is associated with an open session)"
|
||||
);
|
||||
|
|
|
@ -77,7 +77,7 @@ public class LazyOneToOneRemoveFlushAccessTest {
|
|||
catch (Exception e) {
|
||||
if ( shouldThrow ) {
|
||||
assertThat( e.getCause() ).isInstanceOf( TransientObjectException.class )
|
||||
.hasMessageContaining( "persistent instance references an unsaved transient instance" );
|
||||
.hasMessageContaining( "references an unsaved transient instance" );
|
||||
}
|
||||
else {
|
||||
fail( "Test should work with transient strictness disabled, instead threw", e );
|
||||
|
|
|
@ -1285,7 +1285,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
s.setReadOnly( dpLoaded, true );
|
||||
checkReadOnly( s, dpLoaded, true );
|
||||
assertFalse( Hibernate.isInitialized( dpLoaded ) );
|
||||
DataPoint dpMerged = (DataPoint) s.merge( dp );
|
||||
DataPoint dpMerged = s.merge( dp );
|
||||
assertSame( dpLoaded, dpMerged );
|
||||
assertTrue( Hibernate.isInitialized( dpLoaded ) );
|
||||
assertEquals( "changed", dpLoaded.getDescription() );
|
||||
|
@ -1336,7 +1336,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
checkReadOnly( s, dpLoaded, false );
|
||||
s.setReadOnly( dpLoaded, true );
|
||||
checkReadOnly( s, dpLoaded, true );
|
||||
DataPoint dpMerged = (DataPoint) s.merge( dp );
|
||||
DataPoint dpMerged = s.merge( dp );
|
||||
assertSame( dpLoaded, dpMerged );
|
||||
assertEquals( "changed", dpLoaded.getDescription() );
|
||||
checkReadOnly( s, dpLoaded, true );
|
||||
|
@ -1385,7 +1385,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
s.setReadOnly( dpLoaded, true );
|
||||
checkReadOnly( s, dpLoaded, true );
|
||||
assertFalse( Hibernate.isInitialized( dpLoaded ) );
|
||||
DataPoint dpMerged = (DataPoint) s.merge( dpEntity );
|
||||
DataPoint dpMerged = s.merge( dpEntity );
|
||||
assertSame( dpLoaded, dpMerged );
|
||||
assertTrue( Hibernate.isInitialized( dpLoaded ) );
|
||||
assertEquals( "changed", dpLoaded.getDescription() );
|
||||
|
@ -1437,7 +1437,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
checkReadOnly( s, dpLoaded, false );
|
||||
s.setReadOnly( dpLoaded, true );
|
||||
checkReadOnly( s, dpLoaded, true );
|
||||
DataPoint dpMerged = (DataPoint) s.merge( dpEntity );
|
||||
DataPoint dpMerged = s.merge( dpEntity );
|
||||
assertSame( dpLoaded, dpMerged );
|
||||
assertEquals( "changed", dpLoaded.getDescription() );
|
||||
checkReadOnly( s, dpLoaded, true );
|
||||
|
@ -1484,7 +1484,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
assertFalse( s.isReadOnly( dpEntity ) );
|
||||
s.setReadOnly( dpEntity, true );
|
||||
assertTrue( s.isReadOnly( dpEntity ) );
|
||||
DataPoint dpMerged = (DataPoint) s.merge( dp );
|
||||
DataPoint dpMerged = s.merge( dp );
|
||||
assertSame( dpEntity, dpMerged );
|
||||
assertEquals( "changed", dpEntity.getDescription() );
|
||||
assertTrue( s.isReadOnly( dpEntity ) );
|
||||
|
@ -1695,7 +1695,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnly();
|
||||
fail( "should have failed because session was detached" );
|
||||
}
|
||||
catch (TransientObjectException ex) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertFalse( ( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnlySettingAvailable() );
|
||||
}
|
||||
|
@ -1729,7 +1729,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
s.isReadOnly( dp );
|
||||
fail( "should have failed because proxy was detached" );
|
||||
}
|
||||
catch (TransientObjectException ex) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertFalse( ( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnlySettingAvailable() );
|
||||
}
|
||||
|
@ -1759,7 +1759,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnly();
|
||||
fail( "should have failed because proxy was detached" );
|
||||
}
|
||||
catch (TransientObjectException ex) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertFalse( ( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnlySettingAvailable() );
|
||||
}
|
||||
|
@ -1823,7 +1823,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
( (HibernateProxy) dp ).getHibernateLazyInitializer().setReadOnly( true );
|
||||
fail( "should have failed because session was detached" );
|
||||
}
|
||||
catch (TransientObjectException ex) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertFalse( ( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnlySettingAvailable() );
|
||||
}
|
||||
|
@ -1892,7 +1892,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
s.setReadOnly( dp, true );
|
||||
fail( "should have failed because proxy was detached" );
|
||||
}
|
||||
catch (TransientObjectException ex) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertFalse( ( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnlySettingAvailable() );
|
||||
}
|
||||
|
@ -1922,7 +1922,7 @@ public class ReadOnlyProxyTest extends AbstractReadOnlyTest {
|
|||
( (HibernateProxy) dp ).getHibernateLazyInitializer().setReadOnly( true );
|
||||
fail( "should have failed because proxy was detached" );
|
||||
}
|
||||
catch (TransientObjectException ex) {
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
assertFalse( ( (HibernateProxy) dp ).getHibernateLazyInitializer().isReadOnlySettingAvailable() );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue