-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate 4.3.5+old hsql server+new hsql client = problem
PostPosted: Mon Aug 04, 2014 7:51 am 
Newbie

Joined: Mon Aug 04, 2014 7:22 am
Posts: 1
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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.