Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support working with @DataJpaTest #20

Open
Anshelen opened this issue Dec 27, 2020 · 2 comments
Open

Support working with @DataJpaTest #20

Anshelen opened this issue Dec 27, 2020 · 2 comments

Comments

@Anshelen
Copy link

For tests with @DataJpaTest HibernateQueryInterceptor is not registered automatically.

I can not load it somehow cause it is package visible only. Also I tried to add spring.jpa.properties.hibernate.session_factory.interceptor=com.yannbriancon.interceptor.HibernateQueryInterceptor, but without effect. The possible workaround is to copy-paste HibernatePropertiesConfig and add @import({HibernateQueryInterceptor.class, HibernatePropertiesConfig.class}) to test class

@eidottermihi
Copy link

eidottermihi commented Aug 4, 2021

I got it working with @DataJpaTest with the following test config (JUnit 5):

@ExtendWith(SpringExtension.class)
@DataJpaTest
@ComponentScan(basePackages = { "com.yannbriancon" }) // hibernateQueryInterceptor
class RepositoryTest {
  @Autowired
  private HibernateQueryInterceptor hibernateQueryInterceptor;

  // .....
}

@Anshelen
Copy link
Author

Anshelen commented Aug 5, 2021

Solution is working. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants