Skip to content

Add 'mappingLocations' to LocalContainerEntityManagerFactoryBean to scan any JPA mapping files (ORM.xml) in the classpath. [SPR-8440] #13086

Closed

Description

@spring-projects-issues

Donny A. Wijaya opened SPR-8440 and commented

Add 'mappingLocations' to LocalContainerEntityManagerFactoryBean for reading/scanning the JPA mapping files (ORM.xml) in the classpath. This will allow developers to write JPA queries and custom mappings in more modular approach. Developers can easily put the ORM.xml in the same package with the Entity class it relates to.


Affects: 3.1 M2

Issue Links:

Activity

  1. spring-projects-issues commented on Dec 5, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Donny A. Wijaya commented

    Hi Juergen,

    Oliver just added ClasspathScanningPersistenceUnitPostProcessor to solve this mapping files scanning issue(DATAJPA-122). I wonder if it is possible to include this feature permanently at LocalContainerEntityManagerFactoryBean.

    Thanks!!

  2. spring-projects-issues commented on Dec 6, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    I've added a "mappingResources" property to LocalContainerEntityManagerFactoryBean, pointing to orm.xml like files in the classpath. Note that those are not Spring location values but rather classpath resources, similar to the same-named property on the Hibernate LocalSessionFactoryBean. They will be merged into the default persistence unit, just like "packagesToScan" entity classes, and can also be combined with "packagesToScan".

    JPA insists on those file names to be classpath-relative resources, so a URL-based approach won't work in a portable fashion. This is a problem with the Spring Data JPA approach, as far as I can see, since classpath scanning will return URL resources, not classpath-relative locations. This might work with some JPA providers but it won't be portable (to the best of my understanding).

    So with LocalContainerEntityManagerFactoryBea, we expect "mappingResources" to be fully qualified classpath resources a la "META-INF/mappings.xml" or "com/mycompany/repository/mappings.xml". Enumerating them shouldn't be too hard in a typical application; as per the above, we do not support patterns there.

    Juergen

  3. spring-projects-issues commented on Dec 7, 2011

    @spring-projects-issues
    CollaboratorAuthor

    Donny A. Wijaya commented

    Thanks Juergen!! I am going to try it tonight. Thanks for explanation on the JPA specs (I wonder why they didn't follow Spring way of discovering resources which is more modular)

    Having this mappingResources at LocalContainerEntityManagerFactoryBean is a great move. Hopefully, the merging feature in #11189 will remove the needs to configure the mapping files locations there.

  4. added
    in: data
    type: enhancement
    on Jan 11, 2019
  5. added this to the 3.1 GA milestone on Jan 11, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datatype: enhancement

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions