HHH-14821 consistent use of exception types
(and exception message formats)
This commit is contained in:
parent
7e723da507
commit
d234b4eea9
|
@ -9,7 +9,8 @@ package org.hibernate.event.internal;
|
|||
import org.hibernate.HibernateException;
|
||||
import org.hibernate.LockMode;
|
||||
import org.hibernate.LockOptions;
|
||||
import org.hibernate.PersistentObjectException;
|
||||
import org.hibernate.NonUniqueObjectException;
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.UnresolvableObjectException;
|
||||
import org.hibernate.cache.spi.access.CollectionDataAccess;
|
||||
import org.hibernate.cache.spi.access.EntityDataAccess;
|
||||
|
@ -128,8 +129,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
persister = source.getEntityPersister( event.getEntityName(), object );
|
||||
id = persister.getIdentifier( object, event.getSession() );
|
||||
if ( id == null ) {
|
||||
throw new HibernateException( "attempted to refresh an instance that is not part of the persistence context yet: "
|
||||
+ infoString( persister, id, source.getFactory() ));
|
||||
throw new TransientObjectException( "transient instance passed to refresh");
|
||||
}
|
||||
if ( LOG.isTraceEnabled() ) {
|
||||
LOG.tracev(
|
||||
|
@ -138,10 +138,7 @@ public class DefaultRefreshEventListener implements RefreshEventListener {
|
|||
);
|
||||
}
|
||||
if ( persistenceContext.getEntry( source.generateEntityKey( id, persister ) ) != null ) {
|
||||
throw new PersistentObjectException(
|
||||
"attempted to refresh transient instance when persistent instance was already associated with the Session: "
|
||||
+ infoString( persister, id, source.getFactory() )
|
||||
);
|
||||
throw new NonUniqueObjectException( id, persister.getEntityName() );
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -6,8 +6,7 @@ import java.util.HashSet;
|
|||
import java.util.LinkedList;
|
||||
import java.util.Set;
|
||||
|
||||
import org.hibernate.HibernateException;
|
||||
|
||||
import org.hibernate.TransientObjectException;
|
||||
import org.hibernate.testing.orm.junit.DomainModel;
|
||||
import org.hibernate.testing.orm.junit.SessionFactory;
|
||||
import org.hibernate.testing.orm.junit.SessionFactoryScope;
|
||||
|
@ -81,7 +80,7 @@ public class RefreshTest {
|
|||
@Test
|
||||
public void testRefreshWithNullId(SessionFactoryScope scope) {
|
||||
Assertions.assertThrows(
|
||||
HibernateException.class,
|
||||
TransientObjectException.class,
|
||||
() -> {
|
||||
scope.inTransaction(
|
||||
session -> {
|
||||
|
@ -90,8 +89,7 @@ public class RefreshTest {
|
|||
session.refresh( se );
|
||||
}
|
||||
);
|
||||
},
|
||||
"attempted to refresh an instance that is not part of the persistence context yet: [org.hibernate.orm.test.refresh.RefreshTest$SimpleEntity#<null>]"
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue