From http://www.javaeye.com/topic/264448
When using hibernate for standard SQL queries, Oracle's rowid cannot be directly queried:
Java code
- Session. createsqlquery ("select rowid from oracletablename"). List ();
session.createSQLQuery("select rowid from oracletablename").list();
After the query, the program throws the hibernate exception "No dialect mapping for JDBC Type:-8", which literally seems to lack support for a data type. I tried to change the query to the following method: Java code
- Session. createsqlquery ("select length (rowid) Len from oracletablename"). List ();
- Session. createsqlquery ("select nvl2 (rowid,'', rowid) orarowid from oracletablename "). List ();
session.createSQLQuery("select length(rowid) len from oracletablename").list();session.createSQLQuery("select nvl2(rowid,'',rowid) orarowid from oracletablename").list();
The above two methods can successfully query the results, but this requires that rowid must be processed during the query, which is very troublesome. After tracking the source code of hibernate, we found that, the Oracle driver treats rowid as a new type,
Columntype =-8
Columnname = rowid
However, all oracle9idialect or other dialects in hibernate do not register the column type corresponding to-8, so when the program runs to Java code
- Org. hibernate. dialect. typenames. Get (-8 );
org.hibernate.dialect.TypeNames.get(-8);
The error is thrown. Then, rewrite dialect and register the column type corresponding to the-8 rowid In the constructor. Java code
- Public ClassOracle9ior10gdialetExtendsOracle10gdialect {
- PublicOracle9ior10gdialet (){
- Super();
- Super. Registercolumntype (-8, "string"); // The columntype corresponding to rowid is-8, and rowid is treated as a field value.
- Super. Registerhibernatetype (-8, "string ");
- }
- }
Public class oracle9ior10gdialet extends oracle10gdialect {public oracle9ior10gdialet () {super (); super. registercolumntype (-8, "string"); // The columntype corresponding to rowid is-8, and rowid is treated as a field value super. registerhibernatetype (-8, "string ");}}
Register this dialect in the hibernate. cfg. xml configuration file, and then run it again. Everything is OK.
Environment:
Hibernate3.1, jdk1.5, macos10.5.5