Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / Databases / September 2005

Tip: Looking for answers? Try searching our database.

Robust way of storing JDK 5.0 enum values into database

Thread view: 
Kari Ikonen - 25 Sep 2005 16:12 GMT
Basically issue is simple: How to store enum values into database. Sounds
simple, but when going after robust solution, then problems start to
appear.

Some approaches,
- Plenty of manual coding for each enumeration
 * not generic
- Storing enum value names
 * not robust, changes when enum names are changed
- Storing ordinal values
 * not robust, changes when new enum values are added

Thus those approaches won't do the trick.

One potential solution could be something like
http://www.javaspecialists.co.za/archive/Issue113.html

But is there other alternatives?

Signature

KI

Thomas Hawtin - 25 Sep 2005 21:37 GMT
> Basically issue is simple: How to store enum values into database. Sounds
> simple, but when going after robust solution, then problems start to
> appear.

That's rather putting the code before the database. Your enum values are
what database textbooks will refer to as domains. Domains can be
simulated in SQL with a populated table that doesn't change.

> Some approaches,
> - Plenty of manual coding for each enumeration
>   * not generic
> - Storing enum value names
>   * not robust, changes when enum names are changed

If you change the names you break source compatibility.

> - Storing ordinal values
>   * not robust, changes when new enum values are added

If you change the ordinals you break binary compatibility.

If you must allow these things to change, without disrupting existing
data, then I think you want an extra layer of indirection. Expose the
enum in the API, and introduce a new type for the database. Because the
new type represents one of a fixed number of possibilities, an enum is
the obvious choice. But you don't have to change you implementation
until the separation is actually necessary.

Tom Hawtin
Signature

Unemployed English Java programmer
http://jroller.com/page/tackline/



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.