You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
orm.xml should be recognized by default if using JPA [SPR-11234] #15859
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.
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).
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).
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."
Activity
spring-projects-issues commentedon 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 commentedon Dec 18, 2013
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 commentedon Jan 21, 2014
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 commentedon Jul 11, 2015
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 commentedon Jun 17, 2016
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