Hello
Hibernate 4.3.5 does not allow to work well with hsqldb server 1.8 if you are using a newer library on the client side
Here is my setup.
Server-side: third-party hsql server 1.8.0.5 which I cannot change
Client-side: java app which uses Hibernate 4.3.5 and hsqldb 2.3.2
The problem is that a bunch of sql operations would not work. It happens because org.hibernate.dialect.HSQLDialect determines the version of hsqldb from the org.hsqldb.persist.HsqlDatabaseProperties class from the classpath of the app. Here is how it happens
Code:
public HSQLDialect() {
super();
try {
final Class props = ReflectHelper.classForName( "org.hsqldb.persist.HsqlDatabaseProperties" );
final String versionString = (String) props.getDeclaredField( "THIS_VERSION" ).get( null );
hsqldbVersion = Integer.parseInt( versionString.substring( 0, 1 ) ) * 10;
hsqldbVersion += Integer.parseInt( versionString.substring( 2, 3 ) );
}
...
Since I am using the latest hsqldb 2.3.2 lib, the HSQLDialect obtains the version number 2.3.2 from it and it assumes that the server is also 2.3.2 and uses the latest 2.3.2 syntax for queries. For example, if I try to use limit or offset, the following code is used:
Code:
@Override
public String getLimitString(String sql, boolean hasOffset) {
if ( hsqldbVersion < 20 ) {
return new StringBuilder( sql.length() + 10 )
.append( sql )
.insert(
sql.toLowerCase().indexOf( "select" ) + 6,
hasOffset ? " limit ? ?" : " top ?"
)
.toString();
}
else {
return sql + (hasOffset ? " offset ? limit ?" : " limit ?");
}
}
As a result, the HSQLDialect is creating sql queries with hsql 2.3.2 syntax and then those queries are run against 1.8 hsql server which causes a bunch of problems.
The solution I would like to have is to have an option to specify that my server if of another (older) version than the client. At the moment the hsqldbVersion field of HSQLDialect is private and it is used in the constructor of HSQLDialect to register some types, etc... so there is no good way to set this field into desired value.
Are there any good ways to deal with my problem? I would appreciate any suggestions on that topic.
Thank you!