Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
spring-projects-issues opened this issue Dec 16, 2013 · 5 comments
Closed
Assignees
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Dec 16, 2013

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

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Dec 16, 2013

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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

@spring-projects-issues
Copy link
Collaborator Author

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.

@spring-projects-issues
Copy link
Collaborator Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: data Issues in data modules (jdbc, orm, oxm, tx) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants