I agree with the string as db value. reordering or inserting a value, which might make for a more logical order, will break backwards compatibility using ordinals.
Daan On Thu, Aug 1, 2013 at 10:43 PM, Alex Huang <alex.hu...@citrix.com> wrote: > Wido, > > We actually have plenty of places that uses enums. I think you're > specifically talking about saving the ordinal values of an enum into the > database. You can do that easily by putting this annotation on the field. > > @Enumerated(value=EnumType.ORDINAL) > > The DB layer will take care of saving the ordinal value and retrieving and > matching that value back to the enum. > > With that said, I do want to point out that saving ordinal values have > operational issues. The biggest is people forget what they are and have to > keep referring back to documents/code to figure out what it means. The gain > from saving a ordinal value vs the string value in indexing is fairly minimal > due to the range of values being fairly limited in most enum definitions. > Therefore, my preference is to save the String value instead. > > To do that you can use this annotation. > @Enumerated(value=EnumType.STRING) > > There's an example of it in HostVO.java with the Type enum. > > --Alex > > >> -----Original Message----- >> From: Wido den Hollander [mailto:w...@widodh.nl] >> Sent: Thursday, August 1, 2013 11:12 AM >> To: dev@cloudstack.apache.org >> Subject: Do we allow ENUM database types? >> >> Hi, >> >> I'm working on a disk cache setting for per disk offering which allows users >> to >> set it to: >> - none (current behaviour and default) >> - writeback >> - writethrough >> >> I've done some work in the disk-cache branch [0] where I created a new >> column called "cache_mode" in the disk_offering table. >> >> It's currently a varchar(32), but only 3 strings are allowed in the column, >> as >> listed above. >> >> We don't use enums anywhere in the database, so I was wondering if there >> is a good reason for that? >> >> Otherwise I think using a enum here would be a good use-case. >> >> Wido >> >> >> >> >> [0]: >> https://git-wip- >> us.apache.org/repos/asf?p=cloudstack.git;a=shortlog;h=refs/heads/disk- >> cache