Hibernate cannot support Oracle rowid Query

Source: Internet
Author: User

 

From http://www.javaeye.com/topic/264448

When using hibernate for standard SQL queries, Oracle's rowid cannot be directly queried:

Java code
  1. 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

  1. Session. createsqlquery ("select length (rowid) Len from oracletablename"). List ();
  2. 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

  1. 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

  1. Public ClassOracle9ior10gdialetExtendsOracle10gdialect {
  2. PublicOracle9ior10gdialet (){
  3. Super();
  4. Super. Registercolumntype (-8, "string"); // The columntype corresponding to rowid is-8, and rowid is treated as a field value.
  5. Super. Registerhibernatetype (-8, "string ");
  6. }
  7. }
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.