HHH-11762 - PersistenceUnitUtilImpl#getIdentifier throws MappingException for non-entity
This commit is contained in:
parent
3345de7607
commit
912f57bcbf
|
@ -37,6 +37,7 @@ import javax.persistence.spi.LoadState;
|
|||
import javax.persistence.spi.PersistenceUnitTransactionType;
|
||||
|
||||
import org.hibernate.Hibernate;
|
||||
import org.hibernate.MappingException;
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.spi.MetadataImplementor;
|
||||
import org.hibernate.cache.spi.RegionFactory;
|
||||
|
@ -698,9 +699,15 @@ public class EntityManagerFactoryImpl implements HibernateEntityManagerFactory {
|
|||
|
||||
private Object getIdentifierFromPersister(Object entity) {
|
||||
Class<?> entityClass = Hibernate.getClass( entity );
|
||||
EntityPersister persister = emf.getSessionFactory().getEntityPersister( entityClass.getName() );
|
||||
if ( persister == null ) {
|
||||
throw new IllegalArgumentException( entityClass.getName() + " is not an entity" );
|
||||
final EntityPersister persister;
|
||||
try {
|
||||
persister = emf.getSessionFactory().getEntityPersister( entityClass.getName() );
|
||||
if ( persister == null ) {
|
||||
throw new IllegalArgumentException( entityClass.getName() + " is not an entity" );
|
||||
}
|
||||
}
|
||||
catch (MappingException ex) {
|
||||
throw new IllegalArgumentException( entityClass.getName() + " is not an entity", ex );
|
||||
}
|
||||
return persister.getIdentifier( entity, null );
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
/**
|
||||
* @author Steve Ebersole
|
||||
*/
|
||||
|
@ -51,6 +53,28 @@ public class GetIdentifierTest extends BaseEntityManagerFunctionalTestCase {
|
|||
entityManager.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdentifierOfNonEntityTest() {
|
||||
try {
|
||||
entityManagerFactory().getPersistenceUnitUtil().getIdentifier( this );
|
||||
fail( "should have thrown IllegalArgumentException" );
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIdentifierOfNullTest() {
|
||||
try {
|
||||
entityManagerFactory().getPersistenceUnitUtil().getIdentifier( null );
|
||||
fail( "should have thrown IllegalArgumentException" );
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
private NestedLegacyEntity createExisitingNestedLegacyEntity() {
|
||||
|
||||
ModernEntity modernEntity = new ModernEntity();
|
||||
|
|
Loading…
Reference in New Issue