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