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

spring-boot stops when driver could not establish the connection #775

Closed
marvindaviddiaz opened this issue Jan 18, 2019 · 6 comments

Comments

Projects
None yet
4 participants
@marvindaviddiaz
Copy link
Contributor

commented Jan 18, 2019

Application fails when driver could not establish the connection. Is there any possibility to disable ensureSchema method when javers.sqlSchemaManagementEnabled=false?

I am using spring-boot 2.0.1.RELEASE with:

    <dependency>
      <groupId>org.javers</groupId>
      <artifactId>javers-spring-boot-starter-sql</artifactId>
      <version>3.12.1</version>
    </dependency>
    <dependency>
      <groupId>org.javers</groupId>
      <artifactId>javers-persistence-sql</artifactId>
      <version>3.12.1</version>
    </dependency>

application.properties:

javers.sqlSchemaManagementEnabled=false

Stacktrace:


java.sql.SQLRecoverableException: IO Error: The Network Adapter could not establish the connection
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:801)
	at oracle.jdbc.driver.PhysicalConnection.connect(PhysicalConnection.java:782)
	at oracle.jdbc.driver.T4CDriverExtension.getConnection(T4CDriverExtension.java:39)
	at oracle.jdbc.driver.OracleDriver.connect(OracleDriver.java:704)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:117)
	at com.zaxxer.hikari.util.DriverDataSource.getConnection(DriverDataSource.java:123)
	at com.zaxxer.hikari.pool.PoolBase.newConnection(PoolBase.java:365)
	at com.zaxxer.hikari.pool.PoolBase.newPoolEntry(PoolBase.java:194)
	at com.zaxxer.hikari.pool.HikariPool.createPoolEntry(HikariPool.java:460)
	at com.zaxxer.hikari.pool.HikariPool.checkFailFast(HikariPool.java:534)
	at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:115)
	at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:112)
	at org.hibernate.engine.jdbc.connections.internal.DatasourceConnectionProviderImpl.getConnection(DatasourceConnectionProviderImpl.java:122)
	at org.hibernate.internal.NonContextualJdbcConnectionAccess.obtainConnection(NonContextualJdbcConnectionAccess.java:35)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.acquireConnectionIfNeeded(LogicalConnectionManagedImpl.java:106)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getPhysicalConnection(LogicalConnectionManagedImpl.java:136)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.getConnectionForTransactionManagement(LogicalConnectionManagedImpl.java:254)
	at org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl.begin(LogicalConnectionManagedImpl.java:262)
	at org.hibernate.resource.transaction.backend.jdbc.internal.JdbcResourceLocalTransactionCoordinatorImpl$TransactionDriverControlImpl.begin(JdbcResourceLocalTransactionCoordinatorImpl.java:214)
	at org.hibernate.engine.transaction.internal.TransactionImpl.begin(TransactionImpl.java:56)
	at org.springframework.orm.jpa.vendor.HibernateJpaDialect.beginTransaction(HibernateJpaDialect.java:164)
	at org.springframework.orm.jpa.JpaTransactionManager.doBegin(JpaTransactionManager.java:400)
	at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:378)
	at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:137)
	at org.javers.spring.jpa.JaversTransactionalDecorator.ensureSchema(JaversTransactionalDecorator.java:179)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:365)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:308)
	at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:135)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyBeanPostProcessorsBeforeInitialization(AbstractAutowireCapableBeanFactory.java:422)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1694)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:579)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.config.DependencyDescriptor.resolveCandidate(DependencyDescriptor.java:251)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1138)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1065)
	at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:815)
	at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:721)
	at org.springframework.beans.factory.support.ConstructorResolver.autowireConstructor(ConstructorResolver.java:192)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.autowireConstructor(AbstractAutowireCapableBeanFactory.java:1270)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1127)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:541)
	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:501)
	at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:317)
	at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
	at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:315)
	at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199)
	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:760)
	at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:869)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:550)
	at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:140)
	at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:759)
	at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:395)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:327)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
	at com.is4tech.addon.administration.AdministrationApplication.main(AdministrationApplication.java:82)
Caused by: oracle.net.ns.NetException: The Network Adapter could not establish the connection
	at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:569)
	at oracle.net.resolver.AddrResolution.resolveAndExecute(AddrResolution.java:521)
	at oracle.net.ns.NSProtocol.establishConnection(NSProtocol.java:660)
	at oracle.net.ns.NSProtocol.connect(NSProtocol.java:287)
	at oracle.jdbc.driver.T4CConnection.connect(T4CConnection.java:1481)
	at oracle.jdbc.driver.T4CConnection.logon(T4CConnection.java:540)
	... 63 common frames omitted
Caused by: java.io.IOException: Connection refused, socket connect lapse 1 ms. /127.0.0.1 1521 30000 1 true
	at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:229)
	at oracle.net.nt.ConnOption.connect(ConnOption.java:172)
	at oracle.net.nt.ConnStrategy.execute(ConnStrategy.java:508)
	... 68 common frames omitted
Caused by: java.net.ConnectException: Connection refused
	at sun.nio.ch.Net.connect0(Native Method)
	at sun.nio.ch.Net.connect(Net.java:454)
	at sun.nio.ch.Net.connect(Net.java:446)
	at sun.nio.ch.SocketChannelImpl.connect(SocketChannelImpl.java:648)
	at java.nio.channels.SocketChannel.open(SocketChannel.java:189)
	at oracle.net.nt.TimeoutSocketChannel.connect(TimeoutSocketChannel.java:108)
	at oracle.net.nt.TimeoutSocketChannel.<init>(TimeoutSocketChannel.java:86)
	at oracle.net.nt.TcpNTAdapter.connect(TcpNTAdapter.java:188)
	... 70 common frames omitted

2019-01-18 16:43:41.701  WARN 31664 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : SQL Error: 17002, SQLState: 08006
2019-01-18 16:43:41.701 ERROR 31664 --- [           main] o.h.engine.jdbc.spi.SqlExceptionHelper   : IO Error: The Network Adapter could not establish the connection
2019-01-18 16:43:41.709  WARN 31664 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'auditController' defined in file [/TOOLS/workspace/ADDON-TIGO/addon-administration/target/classes/com/is4tech/addon/administration/audit/AuditController.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'javers': Invocation of init method failed; nested exception is org.springframework.transaction.CannotCreateTransactionException: Could not open JPA EntityManager for transaction; nested exception is org.hibernate.exception.JDBCConnectionException: Unable to acquire JDBC Connection
2019-01-18 16:43:41.710  INFO 31664 --- [           main] j.LocalContainerEntityManagerFactoryBean : Closing JPA EntityManagerFactory for persistence unit 'default'
2019-01-18 16:43:41.713  INFO 31664 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]

@mwesolowski

This comment has been minimized.

Copy link
Member

commented Jan 19, 2019

With the property javers.sqlSchemaManagementEnabled set to false, method JaversSchemaManager.ensureSchema is not called and so the schema is not updated.
But in the method JaversTransactionalDecorator.ensureSchema transaction is opened regardless of the value of javers.sqlSchemaManagementEnabled property.
I agree that an application should not fail to start when the database is unavailable. The quickest way to change it is to check the property also in method JaversTransactionalDecorator.ensureSchema. It could look like that:

    public void ensureSchema() {
        if (javersSqlRepository.getConfiguration().isSchemaManagementEnabled()) {
            TransactionTemplate tmpl = new TransactionTemplate(txManager);
            tmpl.execute(new TransactionCallbackWithoutResult() {
                @Override
                protected void doInTransactionWithoutResult(TransactionStatus status) {
                    javersSqlRepository.ensureSchema();
                }
            });
        }
    }

But I'm not sure it's the cleanest way to introduce this behaviour. @bartoszwalacik, what do you think?

@mwesolowski

This comment has been minimized.

Copy link
Member

commented Jan 19, 2019

Or maybe we should think of a different way of triggering JaversTransactionalDecorator.ensureSchema than PostConstruct annotation. I assume it was used to ensure schema update before actual data processing.

@bartoszwalacik

This comment has been minimized.

Copy link
Member

commented Jan 22, 2019

@mwesolowski your solution would be good enough. I don't have a better idea.

@davidfergo

This comment has been minimized.

Copy link

commented Jun 11, 2019

Please, could it be added for the next version? We're having problems with it.
Thanks in advance!

@bartoszwalacik

This comment has been minimized.

Copy link
Member

commented Jun 11, 2019

If you want it to be fixed, consider to contribute.

davidfergo pushed a commit to davidfergo/javers that referenced this issue Jun 11, 2019

bartoszwalacik added a commit that referenced this issue Jun 13, 2019

Merge pull request #847 from davidfergo/master
#775 Solving issue when can't establish connection
@bartoszwalacik

This comment has been minimized.

Copy link
Member

commented Jun 13, 2019

fixed in 5.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.