<?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: 3 ways to serialize Java Enums</title>
	<atom:link href="http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=3-ways-to-serialize-java-enums</link>
	<description>Java, Web 2.0 and other Tech topics</description>
	<lastBuildDate>Thu, 09 Feb 2012 08:01:27 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: James Hogue</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-78683</link>
		<dc:creator>James Hogue</dc:creator>
		<pubDate>Thu, 05 Jan 2012 14:19:02 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-78683</guid>
		<description>You don&#039;t actually need to mark that as @Transient. You&#039;re not supposed to mix method and field annotations in Hibernate so since you&#039;re not actually saving the Color to a field, you don&#039;t need to mark that method as @Transient, which is probably why it worked for apalam. If you saved Color off to a field, it would make sense to then mark the field as @Transient.</description>
		<content:encoded><![CDATA[<p>You don&#8217;t actually need to mark that as @Transient. You&#8217;re not supposed to mix method and field annotations in Hibernate so since you&#8217;re not actually saving the Color to a field, you don&#8217;t need to mark that method as @Transient, which is probably why it worked for apalam. If you saved Color off to a field, it would make sense to then mark the field as @Transient.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vineet</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-56883</link>
		<dc:creator>vineet</dc:creator>
		<pubDate>Fri, 09 Sep 2011 21:23:48 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-56883</guid>
		<description>When you serialize a bean, serializers typically ignore any fields marked as @Transient. You don&#039;t want to store values for fields which are computed. In this case the idea is to only serialize &quot;colorValue&quot; but not Color which is computed from colorValue.

Even if you are not serializing, it is a good practice (IMO) to mark computed fields as @Transient. It makes the code very readable, telling the reader at a quick glance which fields hold information and which fields are computed from other fields.</description>
		<content:encoded><![CDATA[<p>When you serialize a bean, serializers typically ignore any fields marked as @Transient. You don&#8217;t want to store values for fields which are computed. In this case the idea is to only serialize &#8220;colorValue&#8221; but not Color which is computed from colorValue.</p>
<p>Even if you are not serializing, it is a good practice (IMO) to mark computed fields as @Transient. It makes the code very readable, telling the reader at a quick glance which fields hold information and which fields are computed from other fields.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: apalam</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-56881</link>
		<dc:creator>apalam</dc:creator>
		<pubDate>Fri, 09 Sep 2011 21:16:18 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-56881</guid>
		<description>Excellent!!
You have in fact spelled something that is not spelled anywhere - ORMs by default use name.

Could you clarify why is the transient annotation on the getter required? My code is working fine without it. JPA with Hibernate
 - Apalam</description>
		<content:encoded><![CDATA[<p>Excellent!!<br />
You have in fact spelled something that is not spelled anywhere &#8211; ORMs by default use name.</p>
<p>Could you clarify why is the transient annotation on the getter required? My code is working fine without it. JPA with Hibernate<br />
 &#8211; Apalam</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-55254</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Wed, 31 Aug 2011 06:00:06 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-55254</guid>
		<description>java enums are simply great . I have seen a lot many functionality covered by enum but serialization of enum looks new to me but indeed if you are going to store values in database than this is one of the best way.</description>
		<content:encoded><![CDATA[<p>java enums are simply great . I have seen a lot many functionality covered by enum but serialization of enum looks new to me but indeed if you are going to store values in database than this is one of the best way.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raghu</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-43182</link>
		<dc:creator>Raghu</dc:creator>
		<pubDate>Wed, 06 Jul 2011 03:23:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-43182</guid>
		<description>Excellent !!! I was thinking of implementing the same, luckily found the site.</description>
		<content:encoded><![CDATA[<p>Excellent !!! I was thinking of implementing the same, luckily found the site.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SoftwareFads</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-42616</link>
		<dc:creator>SoftwareFads</dc:creator>
		<pubDate>Fri, 01 Jul 2011 20:50:55 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-42616</guid>
		<description>Method 3 is the simplest, shortest and easiest way I have seen to persist enums in Hibernate. It is way less verbose than creating a UserType class, which is the &quot;official&quot; Hibernate solution for enums. Hibernate is a very, very verbose system, requiring endless lines of annotations or XML configuration files. Frankly, Hibernate stinks on ice if it is used in any real world project with even a moderate level of complexity.</description>
		<content:encoded><![CDATA[<p>Method 3 is the simplest, shortest and easiest way I have seen to persist enums in Hibernate. It is way less verbose than creating a UserType class, which is the &#8220;official&#8221; Hibernate solution for enums. Hibernate is a very, very verbose system, requiring endless lines of annotations or XML configuration files. Frankly, Hibernate stinks on ice if it is used in any real world project with even a moderate level of complexity.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: simon</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-35138</link>
		<dc:creator>simon</dc:creator>
		<pubDate>Thu, 05 May 2011 14:50:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-35138</guid>
		<description>your third solution, while i see the versatility advantage, is waaaaaay too verbous.</description>
		<content:encoded><![CDATA[<p>your third solution, while i see the versatility advantage, is waaaaaay too verbous.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: vineet</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-29145</link>
		<dc:creator>vineet</dc:creator>
		<pubDate>Mon, 14 Mar 2011 15:26:34 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-29145</guid>
		<description>Hi, Bernhard - that would work.

My point was that the constant literal value (e.g. RED, GREEN) is a value in the developer realm and should not be directly related to values which are persisted. The expectation of developers is that simply renaming a constant like Color.GREEN should not affect old saved data, which I think it is a reasonable expectation. To me that is not too different than someone telling me that I cannot rename a method because that could break previously persisted data.</description>
		<content:encoded><![CDATA[<p>Hi, Bernhard &#8211; that would work.</p>
<p>My point was that the constant literal value (e.g. RED, GREEN) is a value in the developer realm and should not be directly related to values which are persisted. The expectation of developers is that simply renaming a constant like Color.GREEN should not affect old saved data, which I think it is a reasonable expectation. To me that is not too different than someone telling me that I cannot rename a method because that could break previously persisted data.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bernhard H.</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-29143</link>
		<dc:creator>Bernhard H.</dc:creator>
		<pubDate>Mon, 14 Mar 2011 15:14:59 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-29143</guid>
		<description>Maybe it would be the best solution to assign some kind of a enumSerialVersionUID to your enum and store this along with your values. That way, if you modify the constant names (and you know what serialVersionUIDs are) you&#039;d maybe have the old keys persisting in the database, but you can find and transform them. The enumSerialVersionUID has the advantage that it reminds of a standardized behaviour for serializable obejcts, so it&#039;s a little more obvious in contrast to some business values, isn&#039;t it?</description>
		<content:encoded><![CDATA[<p>Maybe it would be the best solution to assign some kind of a enumSerialVersionUID to your enum and store this along with your values. That way, if you modify the constant names (and you know what serialVersionUIDs are) you&#8217;d maybe have the old keys persisting in the database, but you can find and transform them. The enumSerialVersionUID has the advantage that it reminds of a standardized behaviour for serializable obejcts, so it&#8217;s a little more obvious in contrast to some business values, isn&#8217;t it?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Towid Khan</title>
		<link>http://www.vineetmanohar.com/2010/01/3-ways-to-serialize-java-enums/comment-page-1/#comment-28314</link>
		<dc:creator>Towid Khan</dc:creator>
		<pubDate>Mon, 07 Mar 2011 18:57:17 +0000</pubDate>
		<guid isPermaLink="false">http://www.vineetmanohar.com/?p=762#comment-28314</guid>
		<description>Yup. that is what I meant. While I am on this topic. I have just came up with an idea to make your approach#3 stronger. Why don&#039;t we use a tuple as a key;the String Name along with identifiers to identify the base enum type?

That is,

RED(&quot;RED&quot;,Color.Class)
BLUE(&quot;BLUE&quot;,Color.Class) 

or use random integer in case of class value? 

The motivation behind this is that the developer does not know the exact key and hence cannot change it. of course there is a challenge to map the class type to SQL data type. but Hibernate worry about that :)</description>
		<content:encoded><![CDATA[<p>Yup. that is what I meant. While I am on this topic. I have just came up with an idea to make your approach#3 stronger. Why don&#8217;t we use a tuple as a key;the String Name along with identifiers to identify the base enum type?</p>
<p>That is,</p>
<p>RED(&#8220;RED&#8221;,Color.Class)<br />
BLUE(&#8220;BLUE&#8221;,Color.Class) </p>
<p>or use random integer in case of class value? </p>
<p>The motivation behind this is that the developer does not know the exact key and hence cannot change it. of course there is a challenge to map the class type to SQL data type. but Hibernate worry about that <img src='http://www.vineetmanohar.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

