When attempting to use Hibernate 5.6 in an application that was migrated to Spring 6, I get an exception:

incompatible types: java.lang.Class<javax.persistence.EntityManagerFactory> cannot be converted to java.lang.Class<? extends jakarta.persistence.EntityManagerFactory>

We have tried to use hibernate-core-jakarta as stated in the issue https://github.com/spring-projects/spring-framework/issues/31039. HibernateJpaVendorAdapter is used in the application and the issue seems to be where entityManagerFactory is passed to JpaTransactionManager:

@Bean
public JpaTransactionManager transactionManager(EntityManagerFactory entityManagerFactory) {
    return new JpaTransactionManager(entityManagerFactory);
}

Since Spring 6, the jakarta namespace is used instead of javax and here the new jakarta classes are expected. Shouldn't hibernate-core-jakarta provide a way to use, for example, Hibernate 5.6 but with jakarta?

Comment From: snicoll

Unfortunately, there's nothing actionable. You've found out about hibernate-core-jakarta but you're providing a partial error message with no context and no way for us to know what you're doing.

If you want support, please share a small sample we can run ourselves that reproduces the issue. However, I suspect you'll find out the problem in your arrangement in doing so. If you do, please report back so that we can update this issue.

Comment From: jhoeller

We compile and run our core spring-orm integration tests against hibernate-core-jakarta 5.6.15, so this should definitely be compatible. With such an exception message as shown above, you still got some precompiled classes using javax.persistence.EntityManagerFactory around; please double-check your build setup to consistently use Jakarta Persistence 3.0 compatible artifacts there.

Comment From: sjaks

I can now confirm that JpaTransactionManager accepts the given entityManagerFactory coming from Jakarta.

The issue was caused by having both hibernate-core and hibernate-core-jakarta in the dependencies.