[opencms-dev] ORDER BY strange problem (solution provided)

Pere Torrodellas ptorrodellas at fihoca.com
Thu Jan 19 12:33:07 CET 2006


Hello,

We have been fighting against a very strange situation involving OpenCms, to
which we found a bypass. I'd like to report it both to get an explanation if
someone can provide one, and to provide the bypass for anyone running into
the same problem.

The case is about the result of an ORDER BY clause in an Oracle DB SELECT
statement:

SELECT  NOM_CURS_CAT
  FROM CURSOS
  ORDER BY NOM_CURS_CAT;

Result (partial) when executed by a module class in OpenCms:

A DONA'T
ACCIO FORMATIVA POLIVALENT I
ACCIO FORMATIVA POLIVALENT II
ACCIONS PER DONES EMPRENADORES
ACCIÓ INTEGRADA
ACCIÓ INTEGRAL D'ACOMPANYAMENT A LA INSERCIÓ LABORAL PER A JOVES
ACONSEGUINT 1 FEINA
Acció amb formació polivalent de manteniment i comerç
Acció amb qüalificació en intervenció d'interiors
Acompanyament a la inserció  de persones amb discapacitat

Result (partial) when executed by the same class, same driver, same DB, same
JDK, in a test application, or from an utility (DbVisualizer):

A DONA'T
Acció amb formació polivalent de manteniment i comerç
Acció amb qüalificació en intervenció d'interiors
ACCIO FORMATIVA POLIVALENT I
ACCIO FORMATIVA POLIVALENT II
ACCIÓ INTEGRADA
ACCIÓ INTEGRAL D'ACOMPANYAMENT A LA INSERCIÓ LABORAL PER A JOVES
ACCIONS PER DONES EMPRENADORES
Acompanyament a la inserció  de persones amb discapacitat
Acompanyament a la inserció de persones amb discapacitat
ACONSEGUINT 1 FEINA

Obviously, the first ordering is by ASCII code (binary) and the second is
alphabetic.

Now the mistery:

- The DB and table are the same
- The JDBC driver is the same (same .jar)
- The Java JDK is the same
- The executing classes are the same
- Same results when using a Tomcat DataSource or not.
- Even when executed under the same Tomcat and same JDBC jar (in common/lib
and verifying that it's not in the webapps libs), the result is different
BUT, now the strangest part: only if the applications are not there at the
same time, i.e.
    * If we delete OpenCms from /webapps, the test application behaves as it
does stand-alone.
    * If we add OpenCms and restart Tomcat, the test application behaves as
Opencms!!

The solution bypass is to modify the OpenCms module statement:

SELECT  NOM_CURS_CAT
  FROM CURSOS
  ORDER BY nlssort(NOM_CURS_CAT,'NLS_SORT=SPANISH')

With this, the OpenCms module behaves as the other applications.

So, the questions are:

- Why does the OpenCms module need this specific option and not the other
applications?

- Why does the test application modify its behaviour when OpenCms is in the
same Tomcat? Does OpenCms influence the JDBC driver or the connections in
some way?

Any comment very welcome!

Pere




More information about the opencms-dev mailing list