I am trying to deploy my spring + Hibernate application on JBOSS. while i am starting the server, server start is getting hung. Last entry in the start up log is -
DEBUG: org.springframework.jdbc.datasource.DriverManagerDataSource - Creating new JDBC DriverManager Connection to [myDatabaseURL]
In my application there are around 80 hibernate mapping file. when I am removing all of them excluding one simple basic mapping file, application is able to connect to the DB.
I also try to connect to DB using PLSQL developer and I was able to connect. So in other words DB is working fine.
Any suggestion or pointer for debug ? What can be possible reasons which i am overlooking?
Thanks
Related
We are using spring boot, apache camel and multiple datasources.
spring boot version: 1.5.9 release
primary database: postgres
Secondary database:oracle
We have deployed spring boot jar in linux server.
Datasource properties for postgres is
x.datasource.url=
x.datasource.username=
x.datasource.password=
x.data.jpa.repositories.enabled=true
datasource properties for oracle
y.datasource.url=
y.datasource.username=
y.datasource.password=
y.data.jpa.repositories.enabled=true
when application keeps ideal and After some times we are trying first request failed and getting error jdbc connection failed but it is working in second request without restarting.
please let me know how to keep database active.
You can use hikari connection pool. Refer to this on how to implement. You can configure no. of connections you want to keep with db
I am working in modernizing an existing REST services and moving from OnPrem to AWS.
The legacy application
deployed in a OnPrem Liberty Server
MS SQL server DB was used.
Spring/Hibernate was the core technologies.
New Application Details :
Spring Boot deployed in the AWS environment in a docker container
Server-Tomcat embedded with the Spring boot.
Database is the existing MS Sql server and it is located OnPrem
Some queries which were earlier took less that 500ms to execute is now taking upto 2000ms. The queries,logic and other code related thigs are same between the legacy and the new application. We are not able to find why the queries are taking more time in this.
In the legacy application we had used the server.xml to configure the data source and in the new application we have configured the data source in the Spring boot application.properties . Below are the Datasource configurations:
Liberty Server datasource :
<dataSource id="Microsoft SQL Server JDBC Driver - DataSource - JVM3" jndiName="jdbc/xxx" containerAuthDataRef="yyy" statementCacheSize="50" isolationLevel="TRANSACTION_READ_COMMITTED">
<jdbcDriver libraryRef="MSSQLJDBCLib"/>
<properties.microsoft.sqlserver databaseName="dbName" serverName="servername.com" portNumber="9999" lockTimeout="2000" packetSize="4096" sendStringParametersAsUnicode="false" trustStorePassword="{xor}" beginTranForVendorAPIs="false" freeResourcesOnClose="false" jmsOnePhaseOptimization="false" reauthentication="false" preTestSQLString="SELECT 1" validateNewConnection="false" validateNewConnectionRetryInterval="3" errorDetectionModel="ExceptionMapping" nonTransactionalDataSource="false" name="Microsoft SQL Server JDBC Driver - DataSource - JVM3" enableMultithreadedAccessDetection="false" beginTranForResultSetScrollingAPIs="false" validateNewConnectionRetryCount="100" connectionSharing="1"/>
<connectionManager agedTimeout="-1" connectionTimeout="180" maxIdleTime="300" maxPoolSize="30" minPoolSize="0" reapTime="240" purgePolicy="FailingConnectionOnly"/>
</dataSource>
Spring Boot Datasource :
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName
spring.datasource.hikari.maximumPoolSize=30
spring.datasource.hikari.poolName=SpringBootJPAHikariCP
spring.datasource.hikari.maxLifetime=2000000
spring.datasource.hikari.connectionTimeout=180000
What may be the other parameters which can impact the query performance between the old and the new application?
Note : The ping time between the AWS servers and the OnPrem db takes less than 2ms (very negligible).
The issue is fixed. All the queries which we made to the database were doing an Index scan instead of index seek. That is because we missed the sendStringParametersAsUnicode="false" parameter in the Connection JDBC url.
We changed the connection url to take the required parameters and the queries ran perfectly fine.
spring.datasource.url=jdbc:sqlserver://server.com:9999;databaseName=dBName;packetSize=4096;sendStringParametersAsUnicode=false
I am trying to deploy my webapp on Tomcat 8 that uses Mybatis 3.2.7 and c3p0 for connection pooling to connect to an SQLServer database. I have the sqljdbc4.jar in my classpath. I query the database during my webapp startup to get some values.
The application works in Tomcat 7, however on Tomcat 8, I cannot connect to the database. I debugged a lot using eclipse and the root cause is in the file BasicResourcePool.class file in c3p0 where it is waiting for resource to become available but then throws an java.lang.InterruptedException.
Due to this, Mybatis is throwing a java.SQL.SQLException and thus my webapp does not start as it cannot connect to the database.
Has someone else upgraded to Tomcat 8 and has successfully used Mybatis-c3p0? If yes am I missing something over here?
Solved this. It was JDBC driver issue. Mybatis isn't very good in showing underlying exceptions it seems.
Found this on tomcat 8's documentation:
Thus, the web applications that have database drivers in their
WEB-INF/lib directory cannot rely on the service provider mechanism
and should register the drivers explicitly.
So, I added a Class.forName() with the appropriate driverClass during app startup and this solved my issue.
Consider we have a H2 database which is started from a web-application under Tomcat using Hibernate. In other words it is an embedded H2 database into the application.
The question: is it possible to programmatically stop this H2 server from this application and then start it again?
P.S. Server.createTcpServer(args).start(); or Server.shutdown(...) is not the way, because it is in the embedded mode.
In this particular case such an approach will be a workable solution:
To stop H2 database just use SHUTDOWN sql command:
session.createSQLQuery("SHUTDOWN").executeUpdate();
To restart H2 you don't need to do anything: the Tomcat's connection pool will do it automatically.
What would be the best way to setup/design or simply configure an Hibernate based Java web application to support being started (i.e. sessionfactory initialization) up if the database connectivity is not yet available, but will be, albeit at a much later time.
In other words, is there an easy way to handle out of order initialization between an Hibernate server application and its database?
As far as i know . If you use external connection pool and hibernate is no responsible to making the connections and in additional hbm2ddl is set to none than hibernate should not connect to the database untill you open a session.
Any way if it will failed to open session because there is no connection it will success to open new session as soon as there is databas connectivity.