Home > Software design >  How do I inject Hibernate ClassLoaderService into Spring Boot?
How do I inject Hibernate ClassLoaderService into Spring Boot?

Time:10-26

Hi I need to pass my own ClassLoaderServiceImpl into Hibernate. The issue is that I cannot figure out how to pass it into Hibernate over Spring Boot. How would I do it?

Here is what I got:

ClassLoaderServiceImpl serviceImpl = new ClassLoaderServiceImpl(customClassLoader);
// Magical code that injects serviceImpl into Spring Boot, which will give it to Hibernate

Any help is much appreciated!

CodePudding user response:

That could be tricky.

  1. you need to use specific EntityManagerFactoryBuilderImpl constructor to inject your own implementation of ClassLoaderServiceImpl
  2. spring-orm uses another constructor which does not fit your needs: SpringHibernateJpaPersistenceProvider - thus, you need to override/inherit SpringHibernateJpaPersistenceProvider
  3. next you need to override HibernateJpaVendorAdapter#getPersistenceProvider
  4. after that you will need to override boot auto-configurations.
  • Related