]
Sachinkumar Kantilal Tailor commented on HHH-4407:
--------------------------------------------------
import org.hibernate.type.MappedEnum;
This is very useful code for us. Hope to see in future release. I stuck to create my own
custom enum type which store value instead of ordinal in db. Example show us is very easy.
Will it store value directly ?
Thanks
Sachin
Add support for custom code-based enums in EnumType - such as mapping
ISO codes to gender Enums
-----------------------------------------------------------------------------------------------
Key: HHH-4407
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-4407
Project: Hibernate Core
Issue Type: Improvement
Components: annotations
Reporter: Steve Ebersole
Priority: Minor
Attachments: MappedEnum.java.patch
Now, this could be seen as an improvement to EnumType that's specific to a business
domain, but I'm thinking it could help in the general case. Right now we can map JDK
enums to several database types, such as INT, VARCHAR, etc. Each of these approaches have
some drawbacks, depending on the domain:
1) The int mapping is not very reliable through refactorings. An enum that's mapped
to a "0" or "2" integer value in the database could end up mapped as a
different value if a future refactoring adds an additional enum with an ordinal of 0.
2) The varchar mapping could use the enum name instead of its ordinal. But again, if the
enum changes, the mapping gets lost and it needs manual changes. It's also heavier on
the performance side.
A useful approach for enum mappings is to use common codes to represent them in the
database. That depends of course of the domain logic that's being used. A useful
example is the Human sex mapping, defined in ISO code 5218:
http://en.wikipedia.org/wiki/ISO_5218
* 0 = not known,
* 1 = male,
* 2 = female,
* 9 = not specified.
For this to work, the Sex enum could have a property "isoCode" that specifies
the mapping between the database integer code and the Java enum.
For other domain examples additional examples could be specified.
The EnumType could include a parameter that indicates the property to be evaluated for
code-mapping, performing the translation in this way. Of course, reflection cache /
byte-code generation / whatever could be specified to speed up the process.
As always, patches are offered if you think this improvement is viable.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: