Register custom types with Hibernate

Source: Internet
Author: User

This class must inherit the dialect class corresponding to the database we use. For example, if we use MySql (version 5. x. x), we need to inherit from "org. hibernate. dialect. mySQL5Dialect "; if we use DB2, we should inherit" org. hibernate. dialect. DB2Dialect "; I use Oracle10g, so I want to inherit" org. hibernate. dialect. oracle10gDialect"
In oracle10g, the time and minute are automatically lost, which is an ojdbc driver problem. Therefore, we need to customize the dialect or upgrade the driver.
By default, when the hibernate ing type is java. SQL. Date, you can configure java. SQL. Timestamp for this column.
[Java]
Public class RegisterType extends Oracle10gDialect {
Public RegisterType (){
// TODO Auto-generated constructor stub
Super ();
RegisterHibernateType (Types. CHAR, Hibernate. STRING. getName (); // convert the char type of the database to the String type.
// RegisterHibernateType (Types. DATE, Hibernate. TIMESTAMP. getName ());
// RegisterHibernateType (Types. DECIMAL, Hibernate. BIG_DECIMAL.getName ());
RegisterHibernateType (-1, Hibernate. STRING. getName ());
}
}

Your Oracle uses the decimal type, and the error should be No Dialect mapping for JDBC type: 3. note that this 3 indicates that hibernate cannot map this data type to your java class. it must be used in a custom Dialect:
RegisterHibernateType (Types. DECIMAL, Hibernate. BIG_DECIMAL.getName ());

Register your dialect to hibernate. cfg. xml
[Java]
<Prop key = "hibernate. dialect"> org. zjf. util. RegisterType </prop>

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.