Skip to content

orm.xml should be recognized by default if using JPA [SPR-11234] #15859

Closed

Description

@spring-projects-issues

Hantsy Bai opened SPR-11234 and commented

I used Hibernate as JPA provider and registered a LocalContainerEntityManagerFactoryBean without a persistence.xml.

But when I tried to resgiter a global audit entity listener in orm.xml file, it did not work.

I have to create a empty persistence.xml to make it work.

I think Spring should load the orm.xml by default if JPA is enabled, both with persistence.xml and without persistence.xml.

The related codes is hosted on my github.com

https://github.com/hantsy/spring-sandbox/tree/master/data-audit


Affects: 3.2.6

Issue Links:

Referenced from: commits 4ae893e

0 votes, 5 watchers

Activity

  1. spring-projects-issues commented on Dec 16, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    Have a look at #13086: You can define orm.xml-like resources as "mappingResources" on LocalContainerEntityManagerFactoryBean, with any choice of file name and location.

    Unfortunately, a JPA provider detects orm.xml based on the local of persistence.xml files, with Spring having no direct influence there. So if there is no persistence.xml, there is no default orm.xml according to the persistence provider. However, we can expose <mapping-file> like entries through PersistenceUnitInfo, and this is exactly what "mappingResources" does.

    Juergen

  2. spring-projects-issues commented on Dec 18, 2013

    @spring-projects-issues
    CollaboratorAuthor

    Hantsy Bai commented

    I understand your meanings.

    But Spring can work without a persistence.xml file, it is unreasonable it can not recognize the default orm.xml.

    It is easy to add the orm.xml to mappingResources in LocalContainerEntityManagerFactoryBean by default if it is existed.

  3. spring-projects-issues commented on Jan 21, 2014

    @spring-projects-issues
    CollaboratorAuthor

    Juergen Hoeller commented

    We've addressed this for 4.0.1 now, autodetecting a "META-INF/orm.xml" file in the classpath and using it for Spring's default persistence unit if it is not co-located with a "META-INF/persistence.xml" file (since in case of such co-location, we assume it is intended for use with that persistence.xml file only, like in standard JPA layout).

    Juergen

  4. spring-projects-issues commented on Jul 11, 2015

    @spring-projects-issues
    CollaboratorAuthor

    Hantsy Bai commented

    I found the JPA standard way does not work now, in my case, persistence.xml and orm are existed in /META-INF folder.

    What I wanted is */META-INF/orm.xml *can be detected by Spring, with or without existence of */META-INF/persistence.xml *file.

  5. spring-projects-issues commented on Jun 17, 2016

    @spring-projects-issues
    CollaboratorAuthor

    Cristi Vulpe commented

    I know this is an old issue, but here is my case:
    I recently started to use spring boot version 1.4.0.M3 in conjunction with Spring Data JPA. For reasons related to our project (long story short: we use the same entities for 2 different database vendors and the governance teams follow different naming conventions) we decided not to use annotations but have orm.xml files loaded from different jars (based on the database type).

    All is good, but the problem that I found is that the documentation is not very explicit about the fact that orm.xml will be by default considered. I found this from this post: http://stackoverflow.com/questions/32062828/spring-boot-load-orm-xml, experimented it and it seems to be working just fine.

    Is it possible to update the spring boot documentation and describe one paragraph on this?

    I think a description like the one below would be just fine (assuming technically accurate):
    "If you prefer to avoid entity annotations in order to preserve database independence, you can keep your entity definitions in an META-INF/orm.xml file accessible through the classpath and spring will consider that automatically. This way, you can keep the POJOs clean out of any annotations that might become database-specific."

    cristi

  6. added
    in: data
    type: enhancement
    on Jan 11, 2019
  7. added this to the 4.0.1 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