Using with Hibernate

Problem with MSSQL Server

Hibernate works quite well with Microsoft SQL Server. However, if you are doing complex mappings with <joined-subclass> and reading columns of either TEXT, NTEXT, or IMAGE then you may run into a problem with the Microsoft JDBC driver where you get this error:ResultSet can not re-read row data for column.

The JDBC spec says that:

        For maximum portability, columns within a row should be read 
        in left-to-right order, and each column should only be read once. This 
        reflects implementation limitations in some underlying database protocols
        
However, Hibernate reads columns in whichever order it likes, and reads them multiple times. Most modern JDBC drivers are fine with this.

The MSJdbcProxy code proxies the connections that Hibernate makes to whatever the underlying connection is, regardless of whether it is a JNDI DataSource, a DBCP pool, or a direct connection. It then caches all reads into a Set, and then reads from that set. This avoids the left to right, once only issue.

Using with Hibernate

To proxy the hibernate connection is very simple. Just add this property to your SessionFactory configuration:

        hibernate.connection.provider_class=com.opensourceconnections.msjdbcproxy.HibernateProvider
        

This class will proxy your connection, delegating to whatever connection type you had previously specified.

More Information

Below are links to more information about this issue:

  • http://forum.hibernate.org/viewtopic.php?t=926686
  • http://opensource.atlassian.com/projects/hibernate/secure/ViewIssue.jspa?key=HB-484
  • http://support.microsoft.com/?id=824106