Support Oracle functions with Hibernate

Source: Internet
Author: User
TheOracle9Dialectdialecthasbeendeprecated; useeitherOracle9iDialectorOracle10gDialectinstead that's because Dialect does not

The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead that is because Dialect does not

The Oracle9Dialect dialect has been deprecated; use either Oracle9iDialect or Oracle10gDialect instead
That's because Dialect is undefined. Rewrite the class and register the undefined Dialect ,,
And add it to hibernate. cfg. xml.

Org. hibernate. dialect. OracleCustomDialect

Create a class named OracleCustomDialect

Protected Dialect (){

Log.info ("Using dialect:" + this );

SqlFunctions. putAll (STANDARD_AGGREGATE_FUNCTIONS );

// Standard sql92 functions (can be overridden by subclasses)

RegisterFunction ("substring", new SQLFunctionTemplate (Hibernate. STRING, "substring (? 1 ,? 2 ,? 3 )"));

RegisterFunction ("locate", new SQLFunctionTemplate (Hibernate. INTEGER, "locate (? 1 ,? 2 ,? 3 )"));

RegisterFunction ("trim", new SQLFunctionTemplate (Hibernate. STRING, "trim (? 1? 2? 3? 4 )"));

RegisterFunction ("length", new StandardSQLFunction ("length", Hibernate. INTEGER ));

RegisterFunction ("bit_length", new StandardSQLFunction ("bit_length", Hibernate. INTEGER ));

RegisterFunction ("coalesce", new StandardSQLFunction ("coalesce "));

RegisterFunction ("nullif", new StandardSQLFunction ("nullif "));

RegisterFunction ("abs", new StandardSQLFunction ("abs "));

RegisterFunction ("mod", new StandardSQLFunction ("mod", Hibernate. INTEGER ));

RegisterFunction ("sqrt", new StandardSQLFunction ("sqrt", Hibernate. DOUBLE ));

RegisterFunction ("upper", new StandardSQLFunction ("upper "));

RegisterFunction ("lower", new StandardSQLFunction ("lower "));

RegisterFunction ("cast", new CastFunction ());

RegisterFunction ("extract", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (? 1? 2? 3 )"));


// Map second/minute/hour/day/month/year to ANSI extract (), override on subclasses

RegisterFunction ("second", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (second from? 1 )"));

RegisterFunction ("minute", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (minute from? 1 )"));

RegisterFunction ("hour", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (hour from? 1 )"));

RegisterFunction ("day", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (day from? 1 )"));

RegisterFunction ("month", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (month from? 1 )"));

RegisterFunction ("year", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (year from? 1 )"));

RegisterFunction ("str", new SQLFunctionTemplate (Hibernate. STRING, "cast (? 1 as char )"));


// Register hibernate types for default use in scalar sqlquery type auto detection

RegisterHibernateType (Types. BIGINT, Hibernate. BIG_INTEGER.getName ());

RegisterHibernateType (Types. BINARY, Hibernate. BINARY. getName ());

RegisterHibernateType (Types. BIT, Hibernate. BOOLEAN. getName ());

RegisterHibernateType (Types. CHAR, Hibernate. CHARACTER. getName ());

RegisterHibernateType (Types. DATE, Hibernate. DATE. getName ());

RegisterHibernateType (Types. DOUBLE, Hibernate. DOUBLE. getName ());

RegisterHibernateType (Types. FLOAT, Hibernate. FLOAT. getName ());

RegisterHibernateType (Types. INTEGER, Hibernate. INTEGER. getName ());

RegisterHibernateType (Types. SMALLINT, Hibernate. SHORT. getName ());

RegisterHibernateType (Types. TINYINT, Hibernate. BYTE. getName ());

RegisterHibernateType (Types. TIME, Hibernate. TIME. getName ());

RegisterHibernateType (Types. TIMESTAMP, Hibernate. TIMESTAMP. getName ());

RegisterHibernateType (Types. VARCHAR, Hibernate. STRING. getName ());

RegisterHibernateType (Types. VARBINARY, Hibernate. BINARY. getName ());

RegisterHibernateType (Types. NUMERIC, Hibernate. BIG_DECIMAL.getName ());

RegisterHibernateType (Types. DECIMAL, Hibernate. BIG_DECIMAL.getName ());

RegisterHibernateType (Types. BLOB, Hibernate. BLOB. getName ());

RegisterHibernateType (Types. CLOB, Hibernate. CLOB. getName ());

RegisterHibernateType (Types. REAL, Hibernate. FLOAT. getName ());

Protected Dialect (){

Log.info ("Using dialect:" + this );

SqlFunctions. putAll (STANDARD_AGGREGATE_FUNCTIONS );

// Standard sql92 functions (can be overridden by subclasses)

RegisterFunction ("substring", new SQLFunctionTemplate (Hibernate. STRING, "substring (? 1 ,? 2 ,? 3 )"));

RegisterFunction ("locate", new SQLFunctionTemplate (Hibernate. INTEGER, "locate (? 1 ,? 2 ,? 3 )"));

RegisterFunction ("trim", new SQLFunctionTemplate (Hibernate. STRING, "trim (? 1? 2? 3? 4 )"));

RegisterFunction ("length", new StandardSQLFunction ("length", Hibernate. INTEGER ));

RegisterFunction ("bit_length", new StandardSQLFunction ("bit_length", Hibernate. INTEGER ));

RegisterFunction ("coalesce", new StandardSQLFunction ("coalesce "));

RegisterFunction ("nullif", new StandardSQLFunction ("nullif "));

RegisterFunction ("abs", new StandardSQLFunction ("abs "));

RegisterFunction ("mod", new StandardSQLFunction ("mod", Hibernate. INTEGER ));

RegisterFunction ("sqrt", new StandardSQLFunction ("sqrt", Hibernate. DOUBLE ));

RegisterFunction ("upper", new StandardSQLFunction ("upper "));

RegisterFunction ("lower", new StandardSQLFunction ("lower "));

RegisterFunction ("cast", new CastFunction ());

RegisterFunction ("extract", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (? 1? 2? 3 )"));

// Map second/minute/hour/day/month/year to ANSI extract (), override on subclasses

RegisterFunction ("second", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (second from? 1 )"));

RegisterFunction ("minute", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (minute from? 1 )"));

RegisterFunction ("hour", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (hour from? 1 )"));

RegisterFunction ("day", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (day from? 1 )"));

RegisterFunction ("month", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (month from? 1 )"));

RegisterFunction ("year", new SQLFunctionTemplate (Hibernate. INTEGER, "extract (year from? 1 )"));

RegisterFunction ("str", new SQLFunctionTemplate (Hibernate. STRING, "cast (? 1 as char )"));

// Register hibernate types for default use in scalar sqlquery type auto detection

RegisterHibernateType (Types. BIGINT, Hibernate. BIG_INTEGER.getName ());

RegisterHibernateType (Types. BINARY, Hibernate. BINARY. getName ());

RegisterHibernateType (Types. BIT, Hibernate. BOOLEAN. getName ());

RegisterHibernateType (Types. CHAR, Hibernate. CHARACTER. getName ());

RegisterHibernateType (Types. DATE, Hibernate. DATE. getName ());

RegisterHibernateType (Types. DOUBLE, Hibernate. DOUBLE. getName ());

RegisterHibernateType (Types. FLOAT, Hibernate. FLOAT. getName ());

RegisterHibernateType (Types. INTEGER, Hibernate. INTEGER. getName ());

RegisterHibernateType (Types. SMALLINT, Hibernate. SHORT. getName ());

RegisterHibernateType (Types. TINYINT, Hibernate. BYTE. getName ());

RegisterHibernateType (Types. TIME, Hibernate. TIME. getName ());

RegisterHibernateType (Types. TIMESTAMP, Hibernate. TIMESTAMP. getName ());

RegisterHibernateType (Types. VARCHAR, Hibernate. STRING. getName ());

RegisterHibernateType (Types. VARBINARY, Hibernate. BINARY. getName ());

RegisterHibernateType (Types. NUMERIC, Hibernate. BIG_DECIMAL.getName ());

RegisterHibernateType (Types. DECIMAL, Hibernate. BIG_DECIMAL.getName ());

RegisterHibernateType (Types. BLOB, Hibernate. BLOB. getName ());

RegisterHibernateType (Types. CLOB, Hibernate. CLOB. getName ());

RegisterHibernateType (Types. REAL, Hibernate. FLOAT. getName ());

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.