Announcement Announcement Module
Collapse
No announcement yet.
JPA and how to explicitely list managed classes in the spring configuration Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA and how to explicitely list managed classes in the spring configuration

    I'm trying to find a way to list all managed (i.e. persistent) classes within the entity manager factory (or some other spring managed bean) in order to avoid listing them in META-INF/persistence.xml. The LocalEntityManagerFactoryBean already allows to configure the persistence provider class (which is part of the persistence.xml). I would assume that it should be possible that also the class listing could be moved the the EMF configuration.

    The reason for this approach is to reduce the number of configuration files required and to avoid classpath scanning of annotated classes (yes, all of the managed classes are JPA annotated)!

    Is this already supported? Anybody who has tried to do something similar? Would appreciate any tips on how to proceed with this task! Thanks

  • #2
    Meanwhile I was able to find a first solution myself. I'm sharing this idea in case somebody else needs this too.

    I had a look at the LocalContainerEntityManagerFactoryBean which offers a hook for post processing persistence units that have been retrieved from the found META-INF/persistence.xml. A post processor implementing the interface PersistenceUnitPostProcessor is allowed to modify the persistence unit attributes since it receives a MutablePersistenceUnitInfo.

    So my implementation of the post processor just clears all the managedClasses from the persistence unit info that was passed and adds a list of managedClasses (that are configured as a property of type string list).

    Comment

    Working...
    X