Skip to content
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

After update spring-boot from 1.4.0 to 1.4.1 the file META-INF/orm.xml no longer loaded #6983

Closed
xak2000 opened this issue Sep 21, 2016 · 12 comments
Assignees
Labels
type: bug A general bug type: regression A regression from a previous release
Milestone

Comments

@xak2000
Copy link
Contributor

xak2000 commented Sep 21, 2016

After update spring-boot from 1.4.0 to 1.4.1 the file META-INF/orm.xml no longer loaded.

I have enabled org.hibernate logger to level debug and found this:

Spring Boot 1.4.0 (gradle bootRun):

2016-09-21 20:17:15.555  INFO 14490 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-09-21 20:17:15.571 DEBUG 14490 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : PersistenceUnitInfo [
    name: default
    persistence provider classname: null
    classloader: org.springframework.boot.devtools.restart.classloader.RestartClassLoader@3326fdda
    excludeUnlistedClasses: true
    JTA datasource: null
    Non JTA datasource: org.apache.tomcat.jdbc.pool.DataSource@7061a6eb{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.h2.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE; username=sa; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }
    Transaction type: RESOURCE_LOCAL
    PU root URL: file:/home/xakep/ws/line-meter/build/resources/main
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names [
        point.linemeter.model.Commutator
        point.linemeter.model.Customer
        point.linemeter.model.Employee
        point.linemeter.model.Flat
        point.linemeter.model.House
        point.linemeter.model.LineMeasurement
        point.linemeter.model.LineMeasurementResult
        point.linemeter.model.NetworkNode
        point.linemeter.model.Porch
        point.linemeter.model.Port
        point.linemeter.model.Street
        point.linemeter.model.SubscriberLine]
    Mapping files names [
        META-INF/orm.xml]
    Properties []

Spring Boot 1.4.1 (gradle bootRun):

2016-09-21 20:21:25.991  INFO 15832 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-09-21 20:21:26.008 DEBUG 15832 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : PersistenceUnitInfo [
    name: default
    persistence provider classname: null
    classloader: org.springframework.boot.devtools.restart.classloader.RestartClassLoader@3ac47ba3
    excludeUnlistedClasses: true
    JTA datasource: null
    Non JTA datasource: org.apache.tomcat.jdbc.pool.DataSource@36f8afab{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.h2.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE; username=sa; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=3000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }
    Transaction type: RESOURCE_LOCAL
    PU root URL: file:/home/xakep/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/1.4.1.RELEASE/db60078355dbe57b3ff5efcbf7b411fb5ae75306/spring-boot-autoconfigure-1.4.1.RELEASE.jar
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names [
        point.linemeter.model.Commutator
        point.linemeter.model.Customer
        point.linemeter.model.Employee
        point.linemeter.model.Flat
        point.linemeter.model.House
        point.linemeter.model.LineMeasurement
        point.linemeter.model.LineMeasurementResult
        point.linemeter.model.NetworkNode
        point.linemeter.model.Porch
        point.linemeter.model.Port
        point.linemeter.model.Street
        point.linemeter.model.SubscriberLine]
    Mapping files names []
    Properties []

The main difference here is PU root URL. In first case it is file:/home/xakep/ws/line-meter/build/resources/main and in second case it is file:/home/xakep/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/1.4.1.RELEASE/db60078355dbe57b3ff5efcbf7b411fb5ae75306/spring-boot-autoconfigure-1.4.1.RELEASE.jar.

Also I debug org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager.getOrmXmlForDefaultPersistenceUnit() and found that this line:

        Resource ormXml = this.resourcePatternResolver.getResource(
                this.defaultPersistenceUnitRootLocation + DEFAULT_ORM_XML_RESOURCE);

returns the META-INF/orm.xml resource when used with spring-boot 1.4.0, but the same line returns file:/home/xakep/.gradle/caches/modules-2/files-2.1/org.springframework.boot/spring-boot-autoconfigure/1.4.1.RELEASE/db60078355dbe57b3ff5efcbf7b411fb5ae75306/spring-boot-autoconfigure-1.4.1.RELEASE.jarMETA-INF/orm.xml when used with spring-boot 1.4.1.

It can be not even bug with spring-boot but with spring-orm, but unfortunately I can't debug any futher.

The persistence unit used in my app is default persistence unit. Almost no configuration.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 21, 2016
@xak2000
Copy link
Contributor Author

xak2000 commented Sep 21, 2016

The first post show the result of gradle bootRun, but when I build the project with gradle build and then java -jar it, the issue persists but the PU root URL is ok.

Spring boot 1.4.0:

2016-09-21 20:46:09.589  INFO 23338 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-09-21 20:46:09.609 DEBUG 23338 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : PersistenceUnitInfo [
    name: default
    persistence provider classname: null
    classloader: org.springframework.boot.loader.LaunchedURLClassLoader@31befd9f
    excludeUnlistedClasses: true
    JTA datasource: null
    Non JTA datasource: org.apache.tomcat.jdbc.pool.DataSource@128d2484{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.h2.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE; username=sa; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=30000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }
    Transaction type: RESOURCE_LOCAL
    PU root URL: file:/home/xakep/ws/line-meter/build/libs/line-meter-0.0.1-SNAPSHOT.jar
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names [
        point.linemeter.model.House
        point.linemeter.model.Employee
        point.linemeter.model.SubscriberLine
        point.linemeter.model.Port
        point.linemeter.model.LineMeasurement
        point.linemeter.model.NetworkNode
        point.linemeter.model.Customer
        point.linemeter.model.Flat
        point.linemeter.model.LineMeasurementResult
        point.linemeter.model.Street
        point.linemeter.model.Commutator
        point.linemeter.model.Porch]
    Mapping files names [
        META-INF/orm.xml]
    Properties []

Spring boot 1.4.1:

2016-09-21 20:44:05.373  INFO 22661 --- [           main] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-09-21 20:44:05.391 DEBUG 22661 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : PersistenceUnitInfo [
    name: default
    persistence provider classname: null
    classloader: org.springframework.boot.loader.LaunchedURLClassLoader@31befd9f
    excludeUnlistedClasses: true
    JTA datasource: null
    Non JTA datasource: org.apache.tomcat.jdbc.pool.DataSource@34123d65{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.h2.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE; username=sa; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=3000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }
    Transaction type: RESOURCE_LOCAL
    PU root URL: file:/home/xakep/ws/line-meter/build/libs/line-meter-0.0.1-SNAPSHOT.jar
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names [
        point.linemeter.model.House
        point.linemeter.model.Employee
        point.linemeter.model.SubscriberLine
        point.linemeter.model.Port
        point.linemeter.model.LineMeasurement
        point.linemeter.model.NetworkNode
        point.linemeter.model.Customer
        point.linemeter.model.Flat
        point.linemeter.model.LineMeasurementResult
        point.linemeter.model.Street
        point.linemeter.model.Commutator
        point.linemeter.model.Porch]
    Mapping files names []
    Properties []

The PU root URL is ok in both cases but Mapping files names is empty with spring-boot 1.4.1.

@wilkinsona
Copy link
Member

@xak2000 Can you please provide a small sample that reproduces the problem?

@wilkinsona wilkinsona added the status: waiting-for-feedback We need additional information before we can continue label Sep 21, 2016
@xak2000
Copy link
Contributor Author

xak2000 commented Sep 21, 2016

Of course, I will try tomorrow to reproduce the problem using as small as possible project.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Sep 21, 2016
@xak2000
Copy link
Contributor Author

xak2000 commented Sep 21, 2016

gh-6983.zip

Unpack and run gradle bootRun. See the log:

       Mapping files names []

Then change springBootVersion to 1.4.0.RELEASE in the build.gradle file.
Then run gradle bootRun again and see the log:

       Mapping files names [
          META-INF/orm.xml]

This sample is just clean spring-boot project generated from http://start.spring.io/ site. I only added the META-INF/orm.xml file and enabled the logging.level.org.hibernate.jpa.internal.util.LogHelper = debug logger.

@wilkinsona
Copy link
Member

Thank you. Unfortunately this is a regression caused by the fix for #6635. Thankfully you can work around the problem by adding the following configuration class to your application:

package demo;

import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.orm.jpa.JpaProperties;
import org.springframework.boot.orm.jpa.EntityManagerFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.orm.jpa.JpaVendorAdapter;
import org.springframework.orm.jpa.persistenceunit.PersistenceUnitManager;

@Configuration
public class PersistenceUnitRootWorkaroundConfiguration {

    @Bean
    public EntityManagerFactoryBuilder entityManagerFactoryBuilder(JpaProperties properties,
            JpaVendorAdapter jpaVendorAdapter,
            ObjectProvider<PersistenceUnitManager> persistenceUnitManagerProvider) {
        EntityManagerFactoryBuilder builder = new EntityManagerFactoryBuilder(
                jpaVendorAdapter, properties.getProperties(),
                persistenceUnitManagerProvider.getIfAvailable(),
                null);
        return builder;
    }

}

With this class in place, I see the following output from your sample using 1.4.1.RELEASE:

:bootRun

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::        (v1.4.1.RELEASE)

2016-09-22 16:30:57.378  INFO 7065 --- [  restartedMain] demo.Gh6983Application                   : Starting Gh6983Application on aw-rmbp.home with PID 7065 (/Users/awilkinson/Downloads/gh-6983/build/classes/main started by awilkinson in /Users/awilkinson/Downloads/gh-6983)
2016-09-22 16:30:57.381  INFO 7065 --- [  restartedMain] demo.Gh6983Application                   : No active profile set, falling back to default profiles: default
2016-09-22 16:30:57.422  INFO 7065 --- [  restartedMain] s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@3416d6d2: startup date [Thu Sep 22 16:30:57 BST 2016]; root of context hierarchy
2016-09-22 16:30:58.408  INFO 7065 --- [  restartedMain] j.LocalContainerEntityManagerFactoryBean : Building JPA container EntityManagerFactory for persistence unit 'default'
2016-09-22 16:30:58.428 DEBUG 7065 --- [  restartedMain] o.hibernate.jpa.internal.util.LogHelper  : PersistenceUnitInfo [
    name: default
    persistence provider classname: null
    classloader: org.springframework.boot.devtools.restart.classloader.RestartClassLoader@31b4d013
    excludeUnlistedClasses: true
    JTA datasource: null
    Non JTA datasource: org.apache.tomcat.jdbc.pool.DataSource@1f55a647{ConnectionPool[defaultAutoCommit=null; defaultReadOnly=null; defaultTransactionIsolation=-1; defaultCatalog=null; driverClassName=org.h2.Driver; maxActive=100; maxIdle=100; minIdle=10; initialSize=10; maxWait=30000; testOnBorrow=true; testOnReturn=false; timeBetweenEvictionRunsMillis=5000; numTestsPerEvictionRun=0; minEvictableIdleTimeMillis=60000; testWhileIdle=false; testOnConnect=false; password=********; url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE; username=sa; validationQuery=SELECT 1; validationQueryTimeout=-1; validatorClassName=null; validationInterval=3000; accessToUnderlyingConnectionAllowed=true; removeAbandoned=false; removeAbandonedTimeout=60; logAbandoned=false; connectionProperties=null; initSQL=null; jdbcInterceptors=null; jmxEnabled=true; fairQueue=true; useEquals=true; abandonWhenPercentageFull=0; maxAge=0; useLock=false; dataSource=null; dataSourceJNDI=null; suspectTimeout=0; alternateUsernameAllowed=false; commitOnReturn=false; rollbackOnReturn=false; useDisposableConnectionFacade=true; logValidationErrors=false; propagateInterruptState=false; ignoreExceptionOnPreLoad=false; }
    Transaction type: RESOURCE_LOCAL
    PU root URL: file:/Users/awilkinson/Downloads/gh-6983/build/resources/main
    Shared Cache Mode: UNSPECIFIED
    Validation Mode: AUTO
    Jar files URLs []
    Managed classes names []
    Mapping files names [
        META-INF/orm.xml]
    Properties []

@wilkinsona wilkinsona added type: bug A general bug type: regression A regression from a previous release and removed status: feedback-provided Feedback has been provided status: waiting-for-triage An issue we've not yet triaged labels Sep 22, 2016
@wilkinsona wilkinsona added this to the 1.4.2 milestone Sep 22, 2016
@xak2000
Copy link
Contributor Author

xak2000 commented Sep 22, 2016

Thanks you, Andy! This workaround works like a charm!

@znikola
Copy link

znikola commented Sep 27, 2016

Hi, I have similar issue on 1.4.1 version. I wrote here #6635 where I was asked to open a new issue, but I'm writing here instead.

Basically here is the problem: we are using hbm.xml files for our entity mapping, which means that we have POJO classes as a model without any annotation in them. But, we are using Spring Data JPA repositories.

You can find attached sample project in this comment.

Example.zip

@wilkinsona
Copy link
Member

@znikola You have a separate problem. You're declaring your own JPA configuration so the changes in #6635 won't help you as they only apply to the auto-configured JPA. For the time being at least, you need to call setPersistenceUnitRootLocation on your LocalContainerEntityManagerFactoryBean with an appropriate location. This may stop being necessary in the future, depending on the outcome of #7003 and #7021.

@znikola
Copy link

znikola commented Sep 28, 2016

That location would be location to *hbm.xml mapping files, correct?

@ilyesy

This comment has been minimized.

@snicoll

This comment has been minimized.

@jliuold

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

7 participants