<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaChap Blog &#187; Java</title>
	<atom:link href="http://blog.javachap.com/index.php/category/java/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.javachap.com</link>
	<description>Java and Technology musings for the masses</description>
	<lastBuildDate>Tue, 15 Nov 2011 10:19:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>&#9733; Enumeration Mapping in Hibernate</title>
		<link>http://blog.javachap.com/index.php/enumeration-mapping-in-hibernate/</link>
		<comments>http://blog.javachap.com/index.php/enumeration-mapping-in-hibernate/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 03:25:51 +0000</pubDate>
		<dc:creator>JavaChap</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[annotation]]></category>
		<category><![CDATA[enum]]></category>
		<category><![CDATA[enumeration]]></category>
		<category><![CDATA[hbm]]></category>
		<category><![CDATA[hibernate]]></category>
		<category><![CDATA[java5]]></category>
		<category><![CDATA[mapping]]></category>

		<guid isPermaLink="false">http://blog.javachap.com/?p=566</guid>
		<description><![CDATA[In this simple tutorial i will show you, how to map a Java 5 Enumeration (enum) to a varchar column in Hibernate. The use-case that i'm going to demonstrate is very simple, I have a User class which has a reference to an Enumeration Gender. Gender Enumeration User Domain: Hibernate Mapping (HBM): By default Hibernate [...]]]></description>
			<content:encoded><![CDATA[<p>In this simple tutorial i will show you, how to map a Java 5 Enumeration (enum) to a varchar column in Hibernate. The use-case that i'm going to demonstrate is very simple, I have a <strong>User</strong> class which has a reference to an Enumeration <strong>Gender</strong>. </p>
<h5>Gender Enumeration</h5>
<pre class="brush: java; title: ; notranslate">
package com.javachap.domain.user;
/**
 * Male or Female. Used to customize Account messages (e.g. he or she usage) and
 * to choose the default profile picture.
 */
public enum Gender {
    Male, Female;
}
</pre>
<h5>User Domain:</h5>
<pre class="brush: java; title: ; notranslate">
package com.javachap.domain.user;

public class User {

    private String firstName;
    private String lastName;
    private Gender gender;
    private String email

    /**
     * Gets the &lt;code&gt;User&lt;/code&gt;'s firstName
     *
     * @return the firstName
     */
    public String getFirstName() {
        return firstName;
    }

    /**
     * Sets the &lt;code&gt;User&lt;/code&gt;'s firstName
     *
     * @param firstName the firstName to set
     */
    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    /**
     * Gets the &lt;code&gt;User&lt;/code&gt;'s lastName
     *
     * @return the lastName
     */
    public String getLastName() {
        return lastName;
    }

    /**
     * Sets the &lt;code&gt;User&lt;/code&gt;'s lastName
     *
     * @param lastName the lastName to set
     */
    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    /**
     * Gets the &lt;code&gt;User&lt;/code&gt;'s email
     *
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * Sets the &lt;code&gt;User&lt;/code&gt;'s email
     *
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }
}
</pre>
<h5>Hibernate Mapping (HBM):</h5>
<pre class="brush: xml; title: ; notranslate">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;ISO-8859-1&quot;?&gt;
&lt;!DOCTYPE hibernate-mapping PUBLIC &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;
    &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;

&lt;hibernate-mapping&gt;
  &lt;class table=&quot;user&quot; name=&quot;com.javachap.domain.user.User&quot;&gt;

    &lt;id name=&quot;uid&quot; column=&quot;usr_uid&quot;&gt;
      &lt;generator class=&quot;increment&quot;/&gt;
    &lt;/id&gt;

    &lt;property name=&quot;firstName&quot; type=&quot;java.lang.String&quot; column=&quot;usr_first_name&quot;/&gt;

    &lt;property name=&quot;lastName&quot; type=&quot;java.lang.String&quot; column=&quot;usr_last_name&quot; /&gt;

    &lt;property name=&quot;gender&quot; column=&quot;usr_gender&quot; not-null=&quot;true&quot;&gt;
	  &lt;type name=&quot;org.hibernate.type.EnumType&quot;&gt;
         &lt;param name=&quot;enumClass&quot;&gt;com.javaachap.domain.user.Gender&lt;/param&gt;
         &lt;param name=&quot;type&quot;&gt;12&lt;/param&gt;
      &lt;/type&gt;
    &lt;/property&gt;

    &lt;property name=&quot;email&quot; type=&quot;java.lang.String&quot; column=&quot;usr_email&quot;/&gt;

  &lt;/class&gt;
&lt;/hibernate-mapping&gt;</pre>
<p>By default Hibernate persists the enumeration value as integer in the database when type param is not specified, In order to store the enum display name, we use a param <strong>type</strong>, which should be pointed to value in java.sql.Types. Since we want to store the enum display name in database we have mapped it to <strong>12</strong> which is equivalent to java.sql.Types.VARCHAR<strong>.<br />
</strong></p>
<h5>Hibernate Annotation Based Mapping:</h5>
<p>If you prefer convention over configuration, below is the way to map an enum using annotation.</p>
<pre class="brush: java; title: ; notranslate">
public class User {

   @Enumerated(EnumType.STRING)
   Gender gender

}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.javachap.com/index.php/enumeration-mapping-in-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title><![CDATA[Java 7&#8242;s Fork/Join Framework]]></title>
		<link><![CDATA[http://drdobbs.com/blogs/java/231000556]]></link>
		<comments>http://blog.javachap.com/index.php/java-7s-forkjoin-framework/#comments</comments>
		<pubDate>Sun, 10 Jul 2011 06:24:27 +0000</pubDate>
		<dc:creator>JavaChap</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[features]]></category>
		<category><![CDATA[forkjoin]]></category>
		<category><![CDATA[java7]]></category>
		<category><![CDATA[reference]]></category>

		<guid isPermaLink="false">http://blog.javachap.com/?p=558</guid>
		<description><![CDATA[Eric Bruno: Fork/Join is an enhancement to the ExecutorService implementation that allows you to more easily break up processing to be executed concurrently, and recursively, with little effort on your part. It's based on the work of Doug Lea, a thought leader on Java concurrency, at SUNY Oswego. Fork/Join deals with the threading hassles; you just [...]<p><a href="http://blog.javachap.com/index.php/java-7s-forkjoin-framework/" rel="bookmark" title="Permanent link to 'Java 7&#8242;s Fork/Join Framework'" class="glyph">&#9733;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Eric Bruno:</p>
<blockquote><p>Fork/Join is an enhancement to the <code>ExecutorService</code> implementation that allows you to more easily break up processing to be executed concurrently, and recursively, with little effort on your part. It's based on the work of Doug Lea, a thought leader on Java concurrency, at SUNY Oswego. Fork/Join deals with the threading hassles; you just indicate to the framework which portions of the work can be broken apart and handled recursively. It employs a<em>divide and conquer</em> algorithm that works like this in pseudocode (as taken from <a href="http://gee.cs.oswego.edu/dl/papers/fj.pdf">Doug Lea's paper</a> on the subject):</p></blockquote>
<p><a href="http://drdobbs.com/blogs/java/231000556">http://drdobbs.com/blogs/java/231000556</a></p>
<p><a href="http://blog.javachap.com/index.php/java-7s-forkjoin-framework/" rel="bookmark" title="Permanent link to 'Java 7&#8242;s Fork/Join Framework'" class="glyph">&#9733;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javachap.com/index.php/java-7s-forkjoin-framework/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title><![CDATA[Understanding Java Weak References]]></title>
		<link><![CDATA[http://weblogs.java.net/blog/2006/05/04/understanding-weak-references]]></link>
		<comments>http://blog.javachap.com/index.php/understanding-weak-references/#comments</comments>
		<pubDate>Mon, 04 Jul 2011 07:09:24 +0000</pubDate>
		<dc:creator>JavaChap</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[reference]]></category>
		<category><![CDATA[weak-references]]></category>

		<guid isPermaLink="false">http://blog.javachap.com/?p=540</guid>
		<description><![CDATA[Ethan Nicholas : I'm sure some of you are grumbling by now, as I'm talking about an API which is nearly a decade old and haven't said anything which hasn't been said before. While that's certainly true, in my experience many Java programmers really don't know very much (if anything) about weak references, and I [...]<p><a href="http://blog.javachap.com/index.php/understanding-weak-references/" rel="bookmark" title="Permanent link to 'Understanding Java Weak References'" class="glyph">&#9733;</a></p>
]]></description>
			<content:encoded><![CDATA[<p>Ethan Nicholas :</p>
<blockquote><p>I'm sure some of you are grumbling by now, as I'm talking about an API which is nearly a decade old and haven't said anything which hasn't been said before. While that's certainly true, in my experience many Java programmers really don't know very much (if anything) about weak references, and I felt that a refresher course was needed. Hopefully you at least learned a <em>little</em> something from this review.</p></blockquote>
<blockquote><p>A <em>weak reference</em>, simply put, is a reference that isn't strong enough to force an object to remain in memory. Weak references allow you to leverage the garbage collector's ability to determine reachability for you, so you don't have to do it yourself.</p></blockquote>
<p><a href="http://weblogs.java.net/blog/2006/05/04/understanding-weak-references">http://weblogs.java.net/blog/2006/05/04/understanding-weak-references</a></p>
<p><a href="http://blog.javachap.com/index.php/understanding-weak-references/" rel="bookmark" title="Permanent link to 'Understanding Java Weak References'" class="glyph">&#9733;</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.javachap.com/index.php/understanding-weak-references/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

