When using the PersistenceUnitPostProcessor interface for dynamically injecting Entities and Named Queries in my EntityManagerFactory, I use the method MutablePersistenceUnitInfo.addManagedPackage() to add a package for the EntityManagerFactory scan for entities.
However these packages never get scanned.
If I use the method MutablePersistenceUnitInfo.addManagedClassName() and manually add all the classes in thoses packages it works with no problem.
I'm I doing something wrong?
I have tried using these persistenceProviders with the same end result:
I'm afraid this is not the purpose of addManagedPackage: That method just adds the actual package declaration for annotation inspection, i.e. a package.java with annotations on it. The framework internally calls that method during subpackage scanning.
Package scanning itself is rather driven by setPackagesToScan on LocalContainerEntityManagerFactoryBean / DefaultPersistenceUnitManager and cannot get modified at the PersistenceUnitInfo level anymore (since it already happened before).