From: <leg...@at...> - 2004-05-12 17:30:54
|
The following comment has been added to this issue: Author: Stefano Travelli Created: Wed, 12 May 2004 12:39 PM Body: Agree with the decision. For those who's interested (and to be LGPL compliant for the patched hibernate that I'm distributing) I attach the patch for version 2.1.3. However, I will no longer support this patch for future releases. I'm going to refactor my enumeration types with custom types as Bertrand suggested in the wiki, but I reworked his code in order to have two abstract classes, one for enumerations in numeric fields and one for enumerations in string fields. Enumeration values mapping are provided in the constructor of the concrete type class. Example: public class MyEnumType extends IntEnumType { public MyEnumType() { super(MyEnum.class, new Object[] { MyEnum.FIRST_VALUE, MyEnum.SECOND_VALUE, MyEnum.THIRD_VALUE }, new Object[] { new Integer(1), new Integer(2), new Integer(3) }); } } Or: public class MyEnumType extends StringEnumType { public MyEnumType() { super(MyEnum.class, new Object[] { MyEnum.FIRST_VALUE, MyEnum.SECOND_VALUE, MyEnum.THIRD_VALUE }, new Object[] { "A", "B", "C" }); } } Enumeration classes don't need to be Apache enums. Maybe this will be valuable when we'll have JSR-201 enums. --------------------------------------------------------------------- View this comment: http://opensource.atlassian.com/projects/hibernate/browse/HB-27?page=comments#action_13103 --------------------------------------------------------------------- View the issue: http://opensource.atlassian.com/projects/hibernate/browse/HB-27 Here is an overview of the issue: --------------------------------------------------------------------- Key: HB-27 Summary: Persistent String Enum Type: Patch Status: Closed Priority: Minor Resolution: WON'T FIX Original Estimate: Unknown Time Spent: Unknown Remaining: Unknown Project: Hibernate2 Components: core Assignee: Gavin King Reporter: Max Rydahl Andersen Created: Sat, 3 May 2003 10:15 AM Updated: Wed, 12 May 2004 12:39 PM Description: Persistent String Enum PersistentEnum type is a very userfull feature, but in the legacy data world it happens that some enumerations are stored in "char" columns instead of integer and, as far as I understood, I can map a persistent enumeration only with integer. Mapping my existing data I found several char(2) fields that would be nice to map with an enumeration. I tried to write a patch in order to manage such fields introducing a new Hibernate type PersistentStringEnumType and an interface PersistentStringEnum that one can use as the existing PersistenEnum interface. Please, find the modified classes (TypeFactory, MappingByReflection, Hibernate) and the new one (PersistentStringEnum, PersistentEnum) in the attached zip (for Hibernate 1.2) (BTW: Does someone know a simple way to make a patch against CVS?) It also contains a test case for the feature. The test sources explain how to use it. http://sourceforge.net/tracker/index.php?func=detail&aid=684810&group_id=40712&atid=428711 The lenght of the field must be declared in the mapping through the attribute in the <property> tag. I would be nice if we could set it somewhere in the class that define the PersistentStringEnum, but I can't realize if it's possible. stefano Add a Comment: --------------------------------------------------------------------- JIRA INFORMATION: This message is automatically generated by JIRA. If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa If you want more information on JIRA, or have a bug to report see: http://www.atlassian.com/software/jira |