Spring Boot + JPA (Hibernate) + Atomikos + PostgreSQL = exception!

If you try to use combination of Spring Boot (1.3.3), Spring Data JPA, Atomikos and PostgreSQL database you will probably experience an exception during start of an application.

java.sql.SQLFeatureNotSupportedException: Method org.postgresql.jdbc.PgConnection.createClob() is not yet implemented.
 at org.postgresql.Driver.notImplemented(Driver.java:642) ~[postgresql-9.4.1209.jre7-20160307.201142-10.jar:9.4.1209.jre7-SNAPSHOT]

com.atomikos.datasource.pool.CreateConnectionException: an AtomikosXAPooledConnection with a SessionHandleState with 0 context(s): connection is erroneous
 at com.atomikos.jdbc.AtomikosXAPooledConnection.testUnderlyingConnection(AtomikosXAPooledConnection.java:116) ~[transactions-jdbc-3.9.3.jar:na]

These exceptions appears because JPA (Hibernate) supported by Atomikos is trying to verify PostgreSQL CLOB feature. This feature is not implemented in JDBC driver so driver throws unimportant exception. Unfortunately Atomikos has an exception listener which marks connection as erroneous when any exception occurs.

To suppress this behaviour you have to disable driver's feature detection and configure it's features manually. This is kind of shady undocumented way of how to do it but it works.

# Disable feature detection by this undocumented parameter. Check the org.hibernate.engine.jdbc.internal.JdbcServiceImpl.configure method for more details.
spring.jpa.properties.hibernate.temp.use_jdbc_metadata_defaults = false

# Because detection is disabled you have to set correct dialect by hand.

For more details about configuration of distributed transactions with Atomikos check the Fabio Maffioletti's article.


Remove all NULL checks from table in Microsoft SQL Server 2008

I wanted to create mockup schema based on existing database. I was trying to insert some simple data into pretty complex tables flooded with NOT NULL columns. Unfortunately in MS SQL there's no easy way how to disable NULL checks temporarily so I had to do it permanently. To simplify this task I've used following script generating set of ALTER TABLE commands that removes NULL checks from a table.

This is just a raw solution with few flaws that has to be solved by hand. For example alter commands are generated for identity columns which cannot exist without NULL check.