Spring Framework
  1. Spring Framework
  2. SPR-8440

Add 'mappingLocations' to LocalContainerEntityManagerFactoryBean to scan any JPA mapping files (ORM.xml) in the classpath.

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major Major
    • Resolution: Complete
    • Affects Version/s: 3.1 M2
    • Fix Version/s: 3.1 GA
    • Component/s: Data
    • Labels:
      None
    • Last commented by a User:
      true

      Description

      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.

        Issue Links

          Activity

          Hide
          Donny A. Wijaya added a comment -

          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!!

          Show
          Donny A. Wijaya added a comment - 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!!
          Hide
          Juergen Hoeller added a comment -

          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

          Show
          Juergen Hoeller added a comment - 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
          Hide
          Donny A. Wijaya added a comment -

          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 SPR-6523 will remove the needs to configure the mapping files locations there.

          Show
          Donny A. Wijaya added a comment - 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 SPR-6523 will remove the needs to configure the mapping files locations there.

            People

            • Assignee:
              Juergen Hoeller
              Reporter:
              Donny A. Wijaya
              Last updater:
              Juergen Hoeller
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Days since last comment:
                2 years, 20 weeks ago