Skip to content

Commit

Permalink
HHH-14821 consistent use of exception types
Browse files Browse the repository at this point in the history
(and exception message formats)
  • Loading branch information
gavinking committed Jan 5, 2024
1 parent 942e5cd commit 63a84da
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
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;
Expand Down Expand Up @@ -93,8 +94,7 @@ private static void refresh(RefreshEvent event, RefreshContext refreshedAlready,
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(
Expand All @@ -103,10 +103,7 @@ private static void refresh(RefreshEvent event, RefreshContext refreshedAlready,
);
}
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
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;
Expand Down Expand Up @@ -81,7 +80,7 @@ public void testIt(SessionFactoryScope scope) {
@Test
public void testRefreshWithNullId(SessionFactoryScope scope) {
Assertions.assertThrows(
HibernateException.class,
TransientObjectException.class,
() -> {
scope.inTransaction(
session -> {
Expand All @@ -90,8 +89,7 @@ public void testRefreshWithNullId(SessionFactoryScope scope) {
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>]"
}
);
}

Expand Down

0 comments on commit 63a84da

Please sign in to comment.