try getReference instead of find in Mapper
This commit is contained in:
parent
08bce3d911
commit
7c46fdb36d
@ -87,8 +87,7 @@ abstract class Mapper extends ModelMapper {
|
||||
}
|
||||
|
||||
public <E> E fetchEntity(final String propertyName, final Class<E> entityClass, final Object subEntityUuid) {
|
||||
// using getReference would be more efficient, but results in very technical error messages
|
||||
final var entity = em.find(entityClass, subEntityUuid); // FIXME: try getReference
|
||||
final var entity = em.getReference(entityClass, subEntityUuid);
|
||||
if (entity != null) {
|
||||
return entity;
|
||||
}
|
||||
|
@ -50,7 +50,7 @@ class MapperUnitTest {
|
||||
@Test
|
||||
void mapsBeanWithExistingSubEntity() {
|
||||
final SourceBean givenSource = SourceBean.builder().a("1234").b("Text").s1(new SubSourceBean1(GIVEN_UUID)).build();
|
||||
when(em.find(SubTargetBean1.class, GIVEN_UUID)).thenReturn(new SubTargetBean1(GIVEN_UUID, "xxx"));
|
||||
when(em.getReference(SubTargetBean1.class, GIVEN_UUID)).thenReturn(new SubTargetBean1(GIVEN_UUID, "xxx"));
|
||||
|
||||
final var result = mapper.map(givenSource, TargetBean.class);
|
||||
assertThat(result).usingRecursiveComparison().isEqualTo(
|
||||
@ -81,7 +81,7 @@ class MapperUnitTest {
|
||||
@Test
|
||||
void mapsBeanWithSubEntityNotFound() {
|
||||
final SourceBean givenSource = SourceBean.builder().a("1234").b("Text").s1(new SubSourceBean1(GIVEN_UUID)).build();
|
||||
when(em.find(SubTargetBean1.class, GIVEN_UUID)).thenReturn(null);
|
||||
when(em.getReference(SubTargetBean1.class, GIVEN_UUID)).thenReturn(null);
|
||||
|
||||
final var exception = catchThrowable(() ->
|
||||
mapper.map(givenSource, TargetBean.class)
|
||||
@ -94,7 +94,7 @@ class MapperUnitTest {
|
||||
@Test
|
||||
void mapsBeanWithSubEntityNotFoundAndDisplayName() {
|
||||
final SourceBean givenSource = SourceBean.builder().a("1234").b("Text").s2(new SubSourceBean2(GIVEN_UUID)).build();
|
||||
when(em.find(SubTargetBean2.class, GIVEN_UUID)).thenReturn(null);
|
||||
when(em.getReference(SubTargetBean2.class, GIVEN_UUID)).thenReturn(null);
|
||||
|
||||
final var exception = catchThrowable(() ->
|
||||
mapper.map(givenSource, TargetBean.class)
|
||||
|
Loading…
Reference in New Issue
Block a user