Hibernate to map the enum enum type to type int __hibernate

Source: Internet
Author: User

The most recent mapping of an enumeration type with Hibernate is that in the MySQL database, if you do not configure the type of the enumerated types property in the Hibernate map file, hibernate maps the enum type to the Tinyblob type by default. This is very embarrassing, it seems to spend a lot of resources, to search the Internet, there are a number of solutions if the use of annotation then @enumerated (enumtype.string) can be mapped directly to the STRING type If you use XML configuration is not so simple, the most online method is to use the hibernate provided usertype but this is not the best solution, there is a better way

Package com.igalia.enumerates; public enum Status {BUSY, AVAILABLE;} package com.igalia.entities; Class MyClass {private status status;//getter and Setter}

<class name= "MyClass" > <id name= "id" > <generator class= "native"/> </id> <property name= " Status "> <type name=" Org.hibernate.type.EnumType "> <param name=" Enumclass "> Com.igalia.enumerates.Status </param> </type> </property> </class>

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.