Skip to content

Commit

Permalink
Remove synthetic attribute from SharedEntityManager.
Browse files Browse the repository at this point in the history
AOT no longer needs this bean to be synthetic to work properly. And this attribute hampers BeanPostProcessors from being applied.

See #2730
Original Pull Request: #2866
  • Loading branch information
quaff authored and gregturn committed Jun 14, 2023
1 parent 572efd2 commit f25c24f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ private String registerSharedEntityMangerIfNotAlreadyRegistered(BeanDefinitionRe

AbstractBeanDefinition entityManager = getEntityManagerBeanDefinitionFor(config, null);
entityManager.setRole(BeanDefinition.ROLE_SUPPORT);
entityManager.setSynthetic(true);
entityManager.setPrimary(false);
entityManager.setAutowireCandidate(false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.mockito.junit.jupiter.MockitoSettings;
import org.mockito.quality.Strictness;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.support.AbstractBeanDefinition;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
Expand All @@ -48,6 +49,7 @@
* @author Oliver Gierke
* @author Mark Paluch
* @author Jens Schauder
* @author Yanming Zhou
*/
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
Expand Down Expand Up @@ -147,6 +149,20 @@ void exposesJpaAotProcessor() {
.isEqualTo(JpaRepositoryConfigExtension.JpaRepositoryRegistrationAotProcessor.class);
}

@Test // GH-2730
void shouldNotRegisterEntityManagerAsSynthetic() {

DefaultListableBeanFactory factory = new DefaultListableBeanFactory();

RepositoryConfigurationExtension extension = new JpaRepositoryConfigExtension();
extension.registerBeansForRoot(factory, configSource);

AbstractBeanDefinition bd = (AbstractBeanDefinition) factory.getBeanDefinition("jpaSharedEM_"
+ configSource.getAttribute("entityManagerFactoryRef").orElse("entityManagerFactory"));

assertThat(bd.isSynthetic()).isEqualTo(false);
}

private void assertOnlyOnePersistenceAnnotationBeanPostProcessorRegistered(DefaultListableBeanFactory factory,
String expectedBeanName) {

Expand Down

0 comments on commit f25c24f

Please sign in to comment.