Alex Rivera | Logout

How to handle enumerations without enum fields in a database?

Asked 2009-04-17T16:46:38.810
23

How would I implement a enumeration field in a database that doesn't support enumerations? (i.e. SQLite)

The fields need to be easily searchable with "field = ?" so using any type of data serialization is a bad idea.

Edit
Report

1 Answer

0

This is what I did recently

In my hibernate mapped POJO- I kept the type of the member as String and it is VARCHAR in the database.

The setter for this takes an enum There is another setter which takes String- but this is private (or you can map the field directly- if that's what you prefer.)

Now the fact I am using String is encapsulated from all. For the rest of the application- my domain objects use enum. And as far as the database is concerned- I am using String.

If I missed your question- I apologize.

answered 2009-04-17T17:25:04.410

Your Answer