<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>
<channel>
	<title>Comments on: Modeling enumerated types in the database</title>
	<atom:link href="http://gabrito.com/post/modeling-enumerated-types-in-the-database/feed" rel="self" type="application/rss+xml" />
	<link>http://gabrito.com/post/modeling-enumerated-types-in-the-database</link>
	<description>Anecdotes on Java, Ruby, Sysadmin, SEO, Design, and Management</description>
	<pubDate>Tue, 06 Jan 2009 23:58:51 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: Steve</title>
		<link>http://gabrito.com/post/modeling-enumerated-types-in-the-database/comment-page-1#comment-39839</link>
		<dc:creator>Steve</dc:creator>
		<pubDate>Mon, 18 Jun 2007 04:36:50 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/modeling-enumerated-types-in-the-database#comment-39839</guid>
		<description>Do you know of a good pattern for mapping java 5 enums to a lookup table in hibernate so :
 - You get the ease of using a Java enum in your code 
 - You get the lookup table ensuing FK constraints on the DB as well as lookup tables being a common pattern in legacy databases.

I've been thinking about it ... but haven't come up with anything better than mapping the class normally and then writing a regular java enum where I create a map of lookup table ids to the enum values (and a getter for the id from the enum) ... it works, but it just seems wrong ...</description>
		<content:encoded><![CDATA[<p>Do you know of a good pattern for mapping java 5 enums to a lookup table in hibernate so :<br />
 - You get the ease of using a Java enum in your code<br />
 - You get the lookup table ensuing FK constraints on the DB as well as lookup tables being a common pattern in legacy databases.</p>
<p>I&#8217;ve been thinking about it &#8230; but haven&#8217;t come up with anything better than mapping the class normally and then writing a regular java enum where I create a map of lookup table ids to the enum values (and a getter for the id from the enum) &#8230; it works, but it just seems wrong &#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Uri Boness</title>
		<link>http://gabrito.com/post/modeling-enumerated-types-in-the-database/comment-page-1#comment-1115</link>
		<dc:creator>Uri Boness</dc:creator>
		<pubDate>Wed, 31 May 2006 01:15:33 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/modeling-enumerated-types-in-the-database#comment-1115</guid>
		<description>I don't think it's wise to make it a rule of thumb. In some cases, indeed the database is the proper place for the values for exactly the reasons you mentioned - this is usually the case where the enum type serves some purpose in the domain model. There are other enum types though that serve other purposes... an example for that is user role. In applications where the user roles are static, you can treat it as an enum type, but puting this in the database introduces another downside, which should not be taken lightly... the code *must* be in-sync. with the database at all time. In such situations, I prefer using approach no. 2. Of course, if your requirements can handle it, you can always save string keys instead of integers, so you still keep some documentation in the database (e.g. in case of java 5 enum, you can use the enum name().</description>
		<content:encoded><![CDATA[<p>I don&#8217;t think it&#8217;s wise to make it a rule of thumb. In some cases, indeed the database is the proper place for the values for exactly the reasons you mentioned - this is usually the case where the enum type serves some purpose in the domain model. There are other enum types though that serve other purposes&#8230; an example for that is user role. In applications where the user roles are static, you can treat it as an enum type, but puting this in the database introduces another downside, which should not be taken lightly&#8230; the code *must* be in-sync. with the database at all time. In such situations, I prefer using approach no. 2. Of course, if your requirements can handle it, you can always save string keys instead of integers, so you still keep some documentation in the database (e.g. in case of java 5 enum, you can use the enum name().</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: F. Degenaar</title>
		<link>http://gabrito.com/post/modeling-enumerated-types-in-the-database/comment-page-1#comment-1098</link>
		<dc:creator>F. Degenaar</dc:creator>
		<pubDate>Tue, 30 May 2006 12:39:05 +0000</pubDate>
		<guid isPermaLink="false">http://gabrito.com/post/modeling-enumerated-types-in-the-database#comment-1098</guid>
		<description>There's a 4th kind of solution to this problem located somewhere between option 2 and option 3:
Use option 2 in combination with Java 5 or Jakarta Commeons Enums, but provide only a message key in the toString() method like "com.foobar.EmployeeState.2". The actual output string can be dealt with in a ResourceBundle.
The icing on the cake is to build this ResourceBundle from a database table including the locale data. This way, one can lookup the text mapped to a particular state inside the database, I18N issues are elegantly resolved, and the output texts can be cached inside the application.

Just my 0.02 EUR
Fokko</description>
		<content:encoded><![CDATA[<p>There&#8217;s a 4th kind of solution to this problem located somewhere between option 2 and option 3:<br />
Use option 2 in combination with Java 5 or Jakarta Commeons Enums, but provide only a message key in the toString() method like &#8220;com.foobar.EmployeeState.2&#8243;. The actual output string can be dealt with in a ResourceBundle.<br />
The icing on the cake is to build this ResourceBundle from a database table including the locale data. This way, one can lookup the text mapped to a particular state inside the database, I18N issues are elegantly resolved, and the output texts can be cached inside the application.</p>
<p>Just my 0.02 EUR<br />
Fokko</p>
]]></content:encoded>
	</item>
</channel>
</rss>
