DATAJPA-93 - Don't catch IllegalArgumentExceptions raised by missing domain class in JPA Metamodel.
We now don't catch an IllegalArgumentException being thrown in case a domain class is not found in the metamodel. If it occurs there's nothing we can do about it as we can't come up with an EntityInformation instance then and the persistence provider couldn't handle it anyway.
This commit is contained in:
@@ -58,11 +58,7 @@ public abstract class JpaEntityInformationSupport<T, ID extends Serializable> ex
|
||||
if (Persistable.class.isAssignableFrom(domainClass)) {
|
||||
return new JpaPersistableEntityInformation(domainClass, metamodel);
|
||||
} else {
|
||||
try {
|
||||
return new JpaMetamodelEntityInformation(domainClass, metamodel);
|
||||
} catch (IllegalArgumentException e) {
|
||||
return null;
|
||||
}
|
||||
return new JpaMetamodelEntityInformation(domainClass, metamodel);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,14 +16,18 @@
|
||||
package org.springframework.data.jpa.repository.support;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.metamodel.Metamodel;
|
||||
import javax.persistence.metamodel.SingularAttribute;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.runners.MockitoJUnitRunner;
|
||||
|
||||
/**
|
||||
@@ -34,6 +38,11 @@ import org.mockito.runners.MockitoJUnitRunner;
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class JpaEntityInformationSupportUnitTests {
|
||||
|
||||
@Mock
|
||||
EntityManager em;
|
||||
@Mock
|
||||
Metamodel metaModel;
|
||||
|
||||
@Test
|
||||
public void usesSimpleClassNameIfNoEntityNameGiven() throws Exception {
|
||||
|
||||
@@ -44,6 +53,16 @@ public class JpaEntityInformationSupportUnitTests {
|
||||
assertEquals("AnotherNamedUser", second.getEntityName());
|
||||
}
|
||||
|
||||
/**
|
||||
* @see DATAJPA-93
|
||||
*/
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void rejectsClassNotBeingFoundInMetamodel() {
|
||||
|
||||
when(em.getMetamodel()).thenReturn(metaModel);
|
||||
JpaEntityInformationSupport.getMetadata(User.class, em);
|
||||
}
|
||||
|
||||
static class User {
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user