How do i pass a jdbc paramater using springboot and hibernate? - postgresql

I have an application written with spring-boot (i am new to it so please forgive me if question is dumb) that uses hibernate 4 and postgresql as DB backend.
I noticed a bunch of connections on the DB that belong to the connection pool stating: "SET extra_float_digits = 3"
Googling around, I've found that it is probably due to the use of the old protocol and that could be avoided using the assumeMinServerVersion parameter of the jdbc driver.
Now my question is: how do i pass / set that parameter from a spring-boot application?

According to this page you could set a assumeMinServerVersion parameter in the jdbc url, something like
spring.datasource.url=jdbc:postgresql://localhost/test?assumeMinServerVersion=XYZ

Related

Rails 5 Upgrade Issue: database configuration does not specify adapter

I received the following error after upgrading my application to Rails 5 and it is somewhat cryptic:
...connection_specification.rb:170:in `spec': database configuration does not specify adapter (ActiveRecord::AdapterNotSpecified)
I found the solution to this problem, it turns out that in my case since I was connecting to multiple databases that there was a subtle change in what Rails 5 expected over Rails 4.
If you are connecting to multiple databases the establish_connection used within the model connecting to the separate database requires a symbol instead of a string in Rails 5.
Works
establish_connection :secondary_database
Where as the following no longer works:
establish_connection "secondary_database"
In my case some of my old database connections had used the string argument and were failing, causing me to think that there was an strange incompatibility between Rails 5 and my code base. I thought I would share this as I do not see it documented anywhere specifically.

OrientDB and PostgreSQL JDBC drivers are clashing (InvocationTargetException): is there an OrientDB JAR with everything except JDBC?

My application uses both OrientDB and PostgreSQL databases for different purposes.
It seems they were able to coexist before, but today my code stopped working. Upon debugging, it seems that the OrientDB driver is attempting to connect to my PostgreSQL database when I'm expecting the PostgreSQL driver to connect instead.
Here is the sequence of events:
OrientDB connection is made (using OrientGraphFactory.setupPool()), transaction is started.
Connection attempt is made on PostgreSQL database, error occurs when trying to create the Connection object.
Here is the segment of code that creates the PostgreSQL connection:
Class.forName("org.postgresql.Driver");
Connection connection = DriverManager.getConnection(
"jdbc:postgresql://" + [...]);
return connection;
An InvocationTargetException is thrown at the DriverManager.getConnection() line. Here is the stack trace, clearly indicating that the OrientDB driver was the one trying to connect:
Error on opening database 'jdbc:postgresql://[hostname]/[db_name]'
com.orientechnologies.orient.core.exception.ODatabaseException: Error on opening database 'jdbc:postgresql://[hostname]/[db_name]'
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:204)
at com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx.<init>(ODatabaseDocumentTx.java:168)
at com.orientechnologies.orient.jdbc.OrientJdbcConnection.<init>(OrientJdbcConnection.java:62)
at com.orientechnologies.orient.jdbc.OrientJdbcDriver.connect(OrientJdbcDriver.java:52)
at java.sql.DriverManager.getConnection(DriverManager.java:664)
at java.sql.DriverManager.getConnection(DriverManager.java:247)
Indeed it seems the JDBC drivers are clashing.
I don't actually need JDBC functionality with OrientDB in this case. However, I can't find the OrientDB JAR that doesn't contain JDBC. The home page lets you download JDBC-all or JDBC-only. Where can I find a JAR with all dependencies bundled into a single JAR, but without JDBC?
This is probably not caused by the drivers themselves but by the DriverManager getting "confused" which driver handles which URL.
You can bypass the DriverManager by asking the driver directly for a connection:
Driver drv = new org.postgresql.Driver();
Properties props = new Properties();
props.put("username", "foo_user");
props.put("password", "database_password");
Connection connection = drv.getConnection("jdbc:postgresql://dbhost/db_name", props);
Unrelated, but: Class.forName("org.postgresql.Driver"); is longer necessary with current Java and driver versions.
I solved the problem here:
https://github.com/orientechnologies/orientdb/commit/8e0f4bed41999cf68ae9de229b3ff6a4260813da
It was a misunderstanding on how the DriverManager registers drivers and then calls the getConnection method.
Solutions.
My suggestion is to not use the orientdb-jdbc-all jar at all. If you don't need to work with orient embedded in your app AND access to it via JDBC it is really too big.
Instead, use your dependency management framework (maven, gradle?) to import orient jars, maybe only the orientdb-client if you need to interact with a remote db, maybe more if you need to embed orient in your app.
If you need to interact to a remote Orient Server via JDBC, use only che orientdb-jdbc. But you need the fixed one, so you should build it from source, or wait for next 2.1.8 release.
If you want to stay with the jdbc fat jar, again you can build it from source right now, or you can wait next hotfix release (2.1.8).
hope this help,
best regards

Glassfish datasource implementation different then vendor (postgresql)

I am trying to create a jdbc connection to a postgresql database. I would like to use a datasource. In the documentation of postgresql is stated that one should not use their own implementations of the datasource, but use the implementations of org.apache.commons.dbcp instead. The SharedPoolDatasource looks perfect to me.
The jdbc driver must be postgresql. Glassfish v3.1 offers the opportunity to create a jdbc connection pool. I would like to use that one, but do not know how to make the connection between the commons datasource implementation and the jdbc driver. When I fill in the document on the glassfish server that particular field blanks out forcing me to use the postgresql datasource implementation.
Is this impossible to achieve or do I have to enter data manually in config files? So far I did not have any luck nor feedback. Exceptions should appear in the server.log, but the server.log currently does not show anything (it did show exceptions deploying jsf and ejb applications).
Should be possible....
1. Create a new JDBC Connection Pool:
2. Choose your desired Datasource Implementation Class:
You'll have to setup the details for databasename, user and password in the additional properties tab.
3. Create a new JDBC Resource:

Jasper server datasource timeout setting

I'm using JasperReports Server 4.7 with PostgreSQL 9.1 backend. Trying to set the data source timeout setting but cannot find it in the datasource configuration page. Anyone know where I can set this? I've also searched all the configuration xml files as well.
I don't think you can do it with a JDBC data source (though I'm not certain). But you can certainly set a timeout or a keepalive parameter on a JNDI datasource. Use that instead, and you should be all set.
You can indeed specify a connection timeout in the jdbc url.
example: jdbc://server/database?connectTimeout=<TIMEOUT IN MILLISECONDS>
Check more properties here: http://dev.mysql.com/doc/connector-j/en/connector-j-reference-configuration-properties.html

How to perform direct HQL queries on grails hibernate DB for test purposes in Eclipse

For testing purposes, I'd like to have a console where I can just enter an HQL command and see what it returns on the grails hibernate DB (in my case a MySQL DB) while it's running e.g. in the test environment. What's the best way to do that?
I'm using Eclipse and already came across the JBoss Hibernate Tools, but I'm not sure how to configure them to use my grails MySQL DB. What Type (Core, Annotations, JPA) do I have to choose there and what to fill in the 'Configuration File' / 'Persistence unit' fields? I already set up a property file (see below).
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.driver_class=org.hsqldb.jdbcDriver
hibernate.connection.url=jdbc:mysql://localhost/myproject
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
But is this the best approach anyway?
I am not 100% sure if your close, but the Driver_class property is wrong for MySQL. Try
hibernate.connection.username=sa
hibernate.connection.password=
hibernate.connection.driver_class=com.mysql.jdbc.Driver
hibernate.connection.url=jdbc:mysql://localhost/myproject
hibernate.connection.provider_class=org.hibernate.connection.DriverManagerConnectionProvider
The Class needs to be com.mysql.jdbc.Driver
Hope this helps