<?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>All systems GO</title>
	<atom:link href="http://gokhan.ozar.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://gokhan.ozar.net</link>
	<description>a few things Gökhan Ozar does...</description>
	<lastBuildDate>Tue, 31 Jan 2012 12:33:58 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud &#8211; Part IV</title>
		<link>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-4/</link>
		<comments>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-4/#comments</comments>
		<pubDate>Sun, 29 Jan 2012 23:36:56 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JBoss Seam]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[ORM]]></category>
		<category><![CDATA[RichFaces]]></category>
		<category><![CDATA[Tech Tips]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[tutorial]]></category>
		<category><![CDATA[web application development]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=198</guid>
		<description><![CDATA[In this part of the tutorial we will correct the bugs inherent in version 2.2 of Seam-gen and we will add some code to spice up our blog CMS. First of all, our PostEdit.seam page is not working at all &#8230; <a href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-4/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-213" title="seam-blog-tomcat-part4" src="http://gokhan.ozar.net/wp-content/uploads/seam-blog-tomcat-part4.jpg" alt="Seam Tomcat Deployment Tutorial Part 4" width="600" height="255" /><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>In this part of the tutorial we will correct the bugs inherent in version 2.2 of Seam-gen and we will add some code to spice up our blog CMS.</p>
<p>First of all, our <strong><em>PostEdit.seam</em></strong> page is not working at all as it is. We shall fix this:</p>
<div id="attachment_212" class="wp-caption alignnone" style="width: 1150px"><a href="http://gokhan.ozar.net/wp-content/uploads/sp_fixing_user_edit.png"><img class="size-full wp-image-212" title="sp_fixing_user_edit" src="http://gokhan.ozar.net/wp-content/uploads/sp_fixing_user_edit.png" alt="Fixing the PostEdit.xhtml page" width="1140" height="843" /></a><p class="wp-caption-text">Figure 4.1 - Fixing the PostEdit.xhtml page</p></div>
<p>Open <strong><em>PostEdit.xhtml</em></strong> from the <em>WebContent</em> folder and find the <strong>&lt;rich:tabPanel switchType=&#8221;ajax&#8221;&gt;</strong> block. This is what&#8217;s causing the problem, because it has more than one tab &#8211; one to have the user select a category from a grid on another page, and the second one for selecting a user, since these two entites have <em>@ManyToOne</em> relationships to the post entity, and <em>Seam-gen </em>can&#8217;t handle generating more than one joined object selection user interface item in this version.</p>
<p>I don&#8217;t want an external grid for selection of a category anyway, so we will delete the entire &lt;rich:tabPanel&gt; block on this page, and instead make the category selectable from a pop-up menu using a typical JSF selectOneMenu UI component.</p>
<p>After you delete the &lt;rich:tabPanel&gt; go towards the beginning of the page and locate the code block starting with <strong>&lt;s:decorate id=&#8221;titleField&#8221; template=&#8221;layout/edit.xhtml&#8221;&gt;.<br />
</strong>Within that block replace <strong>&lt;h:inputTextarea id=&#8221;title&#8221; cols=&#8221;80&#8243; rows=&#8221;2&#8243; required=&#8221;true&#8221; value=&#8221;#{postHome.instance.title}&#8221;/&gt;</strong> with &lt;h:inputText id=&#8221;title&#8221; required=&#8221;true&#8221; value=&#8221;#{postHome.instance.title}&#8221;/&gt;</p>
<p>Next, add the following code block below the closing tag (&lt;/s:decorate&gt;) for titleField:</p>
<pre class="brush:xhtml; gutter: false">           &lt;s:decorate id=&quot;categoryField&quot; template=&quot;layout/edit.xhtml&quot;&gt;
                &lt;ui:define name=&quot;label&quot;&gt;Post Category&lt;/ui:define&gt;
                &lt;h:selectOneMenu id=&quot;category&quot;
                           required=&quot;true&quot;
                              value=&quot;#{postHome.instance.title}&quot;&gt;
                     &lt;s:selectItems value=&quot;#{categoryList.resultList}&quot; var=&quot;cat&quot; label=&quot;#{cat.name}&quot; noSelectionLabel=&quot;Please select...&quot; /&gt;
                     &lt;s:convertEntity /&gt;
                &lt;/h:selectOneMenu&gt;
            &lt;/s:decorate&gt;</pre>
<p><span id="more-198"></span>Now find the following after the closing tag of richPanel (&lt;/rich:panel) :</p>
<pre class="brush: xhtml; gutter: false">&lt;h:commandButton id=&quot;save&quot;
              value=&quot;Save&quot;
             action=&quot;#{postHome.persist}&quot;
           disabled=&quot;#{!postHome.wired}&quot;
           rendered=&quot;#{!postHome.managed}&quot;/&gt;</pre>
<p>Replace <em>#{!postHome.wired}</em> with <em>&#8220;false&#8221;</em><br />
so that <strong>disabled=&#8221;false&#8221;</strong>.</p>
<p>Now open <strong>Post.xhtml</strong> and put the following between title and content:</p>
<pre class="brush: xhtml; gutter: true">&lt;s:decorate id=&quot;category&quot; template=&quot;layout/display.xhtml&quot;&gt;
            &lt;ui:define name=&quot;label&quot;&gt;Post Category&lt;/ui:define&gt;
            &lt;h:outputText value=&quot;#{postHome.instance.category.name}&quot;/&gt;
&lt;/s:decorate&gt;</pre>
<p>We also want to display category and user names instead of IDs in the post list. So open PostList.xhtml and find the following (should be at line 69 or somewhere near):</p>
<pre class="brush: xhtml; gutter: false">&lt;ui:param name=&quot;propertyLabel&quot; value=&quot;User id&quot;/&gt;</pre>
<p>Remove &#8221; id&#8221; from the value then three lines below, replace #{_post.user.id} with #{_post.user.name}</p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>Now let&#8217;s make the <em><strong>authenticator</strong></em> authenticate real users from the database. Open Authenticator.java (in net.ozar.blog.session package). After line 16 (@In Credentials credentials) add the following:</p>
<pre class="brush: java; gutter: false">    @In(required = false)
    @Out(required = false, scope = SESSION)
    private User user;
    @In
    private EntityManager entityManager;
    @In
    private FacesMessages facesMessages;</pre>
<p>You may want to</p>
<pre class="brush: java; gutter: true">import net.ozar.blog.entity.User;
import static org.jboss.seam.ScopeType.SESSION;
import org.jboss.seam.annotations.Out;</pre>
<p>(JBoss Tools can fail to auto-guess where to import ScopeType.SESSION.)</p>
<p>Here we are using a Seam-specific technique called &#8220;bijection&#8221; a term invented by makers of Seam. What <strong><em>bijection</em></strong> is basically injecting the User component using <strong>dependency injection</strong>, and also &#8216;outject&#8217;ing it, so that it is made available to both the method handling the event and the subsequent view.</p>
<p>Delete or comment the following and replace it with the code snippet below the following:</p>
<pre class="brush: java; gutter: false">        //write your authentication logic here,
        //return true if the authentication was
        //successful, false otherwise
        if (&quot;admin&quot;.equals(credentials.getUsername()))
        {
            identity.addRole(&quot;admin&quot;);
            return true;
        }
        return false;</pre>
<p>The final version of the <em><strong>Authenticator.java</strong></em> should be like the following:</p>
<pre class="brush: java; gutter: true">package net.ozar.blog.session;

import java.util.List;

import javax.persistence.EntityManager;

import net.ozar.blog.entity.User;
import static org.jboss.seam.ScopeType.SESSION;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Logger;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import org.jboss.seam.log.Log;
import org.jboss.seam.security.Credentials;
import org.jboss.seam.security.Identity;

@Name(&quot;authenticator&quot;)
public class Authenticator
{
    @Logger private Log log;

    @In Identity identity;
    @In Credentials credentials;

    @In(required = false)
    @Out(required = false, scope = SESSION)
    private User user;
    @In
    private EntityManager entityManager;
    @In
    private FacesMessages facesMessages;

    @SuppressWarnings(&quot;unchecked&quot;)
    public boolean authenticate()
    {
        log.info(&quot;authenticating {0}&quot;, credentials.getUsername());
        List&lt;User&gt; adaylar =  entityManager.createQuery(&quot;select u from User u where u.login=#{identity.username} and u.password =#{identity.password}&quot;).getResultList();

        if (adaylar== null || adaylar.size()==0) {
			String msj=&quot;No user by that name or password can be found&quot;;
			log.error(msj);
                        facesMessages.add(msj);
			return false;
		} else {
			user = (User) adaylar.get(0);
			if (user.getLevel()&gt;1 ) identity.addRole(&quot;admin&quot;);
			return true;
		}
    }
}</pre>
<p><em>I will be updating this post shortly demonstrating further optimization to the application and finally deploying it to a server in the cloud. <strong>Stay tuned!</strong></em></p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-4/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud &#8211; Part III</title>
		<link>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-3/</link>
		<comments>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-3/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 16:15:54 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JBoss Seam]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[JSF]]></category>
		<category><![CDATA[RichFaces]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=162</guid>
		<description><![CDATA[In this part III of the tutorial, we&#8217;ll build the entity classes from the database we created in Part I and configure the Seam project we created in Part II so as to make it fully compatible with Apache Tomcat. Contents1 &#8230; <a href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-3/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class=" wp-image-163 alignnone" title="seam-blog-tomcat-part3" src="http://gokhan.ozar.net/wp-content/uploads/seam-blog-tomcat-part3.jpg" alt="Seam Tomcat Deployment" width="600" height="255" /></p>
<p>In this <strong>part III</strong> of the tutorial, we&#8217;ll build the entity classes from the database we created in <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part I" href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-1/">Part I</a> and configure the <em><strong>Seam</strong></em> project we created in <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part II" href="http://gokhan.ozar.net/create-a-blog-with-jboss-seam-hibernate-jpa-and-jsf-then-deploy-it-to-tomcat-in-the-cloud-part-ii/">Part II</a> so as to make it fully compatible with <em><strong>Apache Tomcat</strong></em>.</p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<div id="toc_container" class="no_bullets"><p class="toc_title">Contents</p><ul class="toc_list"><li><a href="#Creating_The_Model_Layer">1 Creating The Model Layer</a></li><li><a href="#Configuring_the_Seam_Project_for_Tomcat_Deployment">2 Configuring the Seam Project for Tomcat Deployment</a><ul><li><a href="#Importing_the_jar_files_into_the_Eclipse_Project">2.1 Importing the .jar files into the Eclipse Project</a></li><li><a href="#Modifying_the_data_source_for_Tomcat">2.2 Modifying the data source for Tomcat</a></li><li><a href="#Running_the_Seam_Blog_Project_for_the_first_time">2.3 Running the Seam Blog Project for the first time</a></li></ul></li></ul></div>
<h2><span id="Creating_The_Model_Layer">Creating The Model Layer</span></h2>
<p>We&#8217;ll use <strong><em>Hibernate</em></strong>&#8216;s reverse engineering tool (hbm2java) embedded in Seam-gen to create the entity classes from the database we created in <em><a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part I" href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-1/">part 1</a></em>.</p>
<div id="attachment_165" class="wp-caption alignnone" style="width: 930px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog19-generate-entities.png"><img class=" wp-image-165" title="eclipse-new-seam-web-proj-blog19-generate-entities" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog19-generate-entities.png" alt="Seam Generate Entities" width="920" height="900" /></a><p class="wp-caption-text">Figure 3.1 - Generating entities from database in JBoss Seam</p></div>
<p>Right-click the project blog in project explorer and select <strong>New &gt; Seam Generate Entities</strong>.</p>
<p><span id="more-162"></span></p>
<div id="attachment_167" class="wp-caption alignnone" style="width: 598px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog20-generate-entities-reveng.png"><img class="size-full wp-image-167" title="eclipse-new-seam-web-proj-blog20-generate-entities-reveng" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog20-generate-entities-reveng.png" alt="Reverse Engineering from database" width="588" height="500" /></a><p class="wp-caption-text">Figure 3.2 - Reverse Engineering from database</p></div>
<p>Select <em><strong>reverse engineer from database</strong></em> and then click &#8216;<em>next</em>&#8216; like shown in figure 3.2.</p>
<div id="attachment_169" class="wp-caption alignnone" style="width: 657px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog21-generate-entities-reveng.png"><img class="size-full wp-image-169" title="eclipse-new-seam-web-proj-blog21-generate-entities-reveng" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog21-generate-entities-reveng.png" alt="Reverse engineering from database (2)" width="647" height="521" /></a><p class="wp-caption-text">Figure 3.3 - Reverse engineering from database (2)</p></div>
<p>To display the database schema in the first place, you may need to hit the refresh button first. Since we set everything up properly (did you, too? <img src='http://gokhan.ozar.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  in Part II, we don&#8217;t need to tackle anything else &#8211; just click Finish.</p>
<div id="attachment_170" class="wp-caption alignright" style="width: 326px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog22-generated-files.png"><img class="size-full wp-image-170 " title="eclipse-new-seam-web-proj-blog22-generated-files" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog22-generated-files.png" alt="Entity classes and the controller classes" width="316" height="645" /></a><p class="wp-caption-text">Figure 3.4 - Seam-generated entity classes and controllers</p></div>
<p>And voilà! After some processing, our entities should show up in the project explorer along with some controller classes as well as the (JSF) <em>xhtml</em> files in the web content as shown in figure 3.4.</p>
<p>The classes with the suffix &#8216;Home&#8217; such as <em>CategoryHome</em> are some sort of a <strong>JSF managed bean</strong> + JPA controller combo&#8217;s. In fact, these classes extend Seam&#8217;s <strong><em>EntityHome</em></strong> class which is pre-built with most of the methods for instantiating the entity object and performing <em>CRUD</em> operations using Seam&#8217;s built-in <em>EntityManager</em>. Likewise, the other classes in the session package with the suffix &#8216;List&#8217; such as <em>CategoryList</em> extend  Seam&#8217;s <strong><em>EntityQuery</em></strong> class which make it easy to perform certain basic persistence queries on entities without having to write so many lines of code to invoke the EntityManager, start transactions and run queries.</p>
<p>In the next section we&#8217;ll do some hacks and mods to the project and make it Tomcat-savvy, so that we can preview what we&#8217;ve done so far by running the application and see it in the browser for ourselves.</p>
<h2><span id="Configuring_the_Seam_Project_for_Tomcat_Deployment">Configuring the Seam Project for Tomcat Deployment</span></h2>
<p>There are a few articles, blog and forum posts all over the Internet which describe how to deploy a Seam application on Tomcat. But in my experience, none of them alone were accurate for deploying Seam 2.2 apps on Tomcat 6 (and perhaps 7, too) without crashing Tomcat at startup. Either one or more of the required jars were never mentioned, or <strong>components.xml</strong> modification was not correctly described.</p>
<p>In this part of the tutorial, I will explain step-by-step what exactly is necessary to be done and which versions of which libraries are exactly the ones to be included in the project so that Tomcat won&#8217;t crash as soon as started up &#8211; and neither your application.</p>
<p>The required library jar files (some of them are already be present in the project as we set up user defined JSF libraries in part II and some of them &#8211; and unfortunately not all of them come with recent versions of Seam):</p>
<ul>
<li>antlr.jar</li>
<li>asm.jar</li>
<li>cglib.jar</li>
<li>commons-beanutils.jar</li>
<li>common-collections.jar</li>
<li>commons-digester.jar</li>
<li>commons-lang.jar</li>
<li>commons-logging.jar</li>
<li>dom4j.jar</li>
<li>hibernate-annotations.jar</li>
<li>hibernate-commons-annotations.jar</li>
<li>hibernate-entitymanager.jar</li>
<li>hibernate.jar</li>
<li>hibernate-validator.jar</li>
<li>javassist.jar</li>
<li>jboss-archive-browsing.jar</li>
<li>jboss-el.jar</li>
<li>jboss-seam-debug.jar</li>
<li>jboss-seam.jar</li>
<li>jboss-seam-ui.jar</li>
<li>jsf-api.jar</li>
<li>jsf-facelets.jar</li>
<li>jsf-impl.jar</li>
<li>jstl.jar</li>
<li>jta.jar</li>
<li>lucene-core.jar</li>
<li>persistence-api.jar</li>
<li>richfaces-api.jar</li>
<li>richfaces-impl.jar</li>
<li>richfaces-ui.jar</li>
<li>\test\hibernate-all.jar</li>
</ul>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>You can download all of these necessary files in a zip file <a title="Downloads | All Systems GO" href="http://gokhan.ozar.net/downloads/?did=3">here</a>. After downloading, decompress them in a folder on your computer and follow the steps in the next section to import them into your project. Please note that since some of them are already present in your project&#8217;s WEB-INF/lib, be sure to uncheck &#8216;overwrite existing files&#8217; option.</p>
<h3><span id="Importing_the_jar_files_into_the_Eclipse_Project">Importing the .jar files into the Eclipse Project</span></h3>
<p>Expand the WebContent folder and then the WEB-INF folder residing inside of it in Eclipse&#8217;s package explorer so that you reveal WEB-INF/lib. Then right-click lib, and select &#8216;Import&#8230;&#8217; from the dropdown menu that pops up.</p>
<div id="attachment_173" class="wp-caption alignnone" style="width: 507px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-library-import1.png"><img class="size-full wp-image-173 " title="eclipse-library-import1" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-library-import1.png" alt="Importing Seam jars into WEB-INF/lib" width="497" height="635" /></a><p class="wp-caption-text">Figure 3.5 - Importing Seam jars into WEB-INF/lib</p></div>
<p>Select &#8216;File System&#8217; as the import source and click &#8216;Next&#8217;. Then select the folder in your file system (i.e. Windows explorer on the PC, or the Finder on the Mac)</p>
<div id="attachment_176" class="wp-caption alignnone" style="width: 646px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-library-import3.png"><img class="size-full wp-image-176" title="eclipse-library-import3" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-library-import3.png" alt="Adding external JARs into your Eclipse Project" width="636" height="774" /></a><p class="wp-caption-text">Figure 3.6 - Copying external JARs into your Eclipse Project from the file system</p></div>
<p>Refer to figure 3.6 and make sure you tick the checkbox next to the name of the folder containing the jar files to select them all at once (if you don&#8217;t want to individually select the checkboxes of the jar files yourself) then make sure of the following:</p>
<ul>
<li>Into folder: <strong>blog/WebContent/WEB-INF/lib</strong> (importing the jars anywhere outside this path will fail you)</li>
<li><em>Overwrite existing resources without warning</em> had better be unchecked. Why? Because if you try this tutorial with a version of <em><strong>Seam</strong></em> other than 2.2, you probably want to keep the original versions of the duplicate jars that shipped with <em>Seam</em> &#8211; for not risking anything to break up.</li>
<li>Create selected folders only is as good as checked. (It should be so by default anyway)</li>
</ul>
<p>Click Finish to start importing the Seam libraries from the file system.</p>
<div id="attachment_178" class="wp-caption alignnone" style="width: 532px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-library-import4.png"><img class="size-full wp-image-178" title="eclipse-library-import4" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-library-import4.png" alt="Dealing with duplicate libraries in the import process" width="522" height="142" /></a><p class="wp-caption-text">Figure 3.7 - Dealing with duplicate Seam libraries in the import process</p></div>
<p>In case you&#8217;re asked what to do about overwriting some of the libraries already existing in your project, go with <em><strong>&#8216;No to All&#8217;</strong></em>. Because if you try this tutorial with a version of<em><strong> Seam other than 2.2</strong></em>, you probably want to keep the original versions of the duplicate jars that shipped with Seam &#8211; for not risking anything to break up.</p>
<h3><span id="Modifying_the_data_source_for_Tomcat">Modifying the data source for Tomcat</span></h3>
<p>Every Seam project created with Seam-Gen or JBoss Tools comes with a datasource definition in XML format called &#8216;blog-ds.xml&#8217; residing in a folder called &#8216;resources&#8217; in the project folder. This approach of &#8216;deploying the datasource to the server&#8217; suits the JBoss AS very well, but in the case of Tomcat, the portable datasource definition file is useless and we need to define the datasource differently on Tomcat so as to have it supply us the database connection when running our application.</p>
<p>Therefore we will now create a file named context.xml in our WebContent/META-INF folder and create a new resource there. Fill the <strong>context.xml</strong> with the following definitions:</p>
<pre class="brush: java; gutter: true">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;

&lt;Context docBase=&quot;blog&quot; path=&quot;/blog&quot; reloadable=&quot;true&quot;&gt;

  &lt;Resource auth=&quot;Container&quot; driverClassName=&quot;com.mysql.jdbc.Driver&quot;
  maxActive=&quot;20&quot; maxIdle=&quot;10&quot; maxWait=&quot;-1&quot; name=&quot;jdbc/seamblog&quot;
  password=&quot;12345&quot;
  type=&quot;javax.sql.DataSource&quot; url=&quot;jdbc:mysql://localhost:3306/seamblog&quot;
  username=&quot;blogger&quot; /&gt;

&lt;/Context&gt;</pre>
<p>Now we need to handle the other configuration files which use this connection. First of them is <strong>persistence.xml</strong> is which contains the definition of our JPA persistence unit. We need to change the jta-data-source value which is normally intended for a container-managed transaction such as on JBoss AS. Since we&#8217;re working for Tomcat deployment here, we need to change the transaction type to the local resource in persistence.xml.</p>
<p><span style="color: #ff0000;"></span></p>
<p>Open persistence.xml (src/main/META-INF/persistence.xml) and modify the persistence unit so as to resemble the following:</p>
<pre class="brush: java; gutter: true">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;persistence-unit name=&quot;seamblogPU&quot; transaction-type=&quot;RESOURCE_LOCAL&quot;&gt;
      &lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
      &lt;jta-data-source&gt;java:comp/env/jdbc/seamblog&lt;/jta-data-source&gt;
      &lt;properties&gt;
         &lt;property name=&quot;hibernate.dialect&quot; value=&quot;org.hibernate.dialect.MySQLInnoDBDialect&quot;/&gt;
         &lt;property name=&quot;hibernate.hbm2ddl.auto&quot; value=&quot;validate&quot;/&gt;
         &lt;property name=&quot;hibernate.show_sql&quot; value=&quot;true&quot;/&gt;
         &lt;property name=&quot;hibernate.format_sql&quot; value=&quot;true&quot;/&gt;         
         &lt;property name=&quot;hibernate.default_catalog&quot; value=&quot;seamblog&quot;/&gt;
         &lt;property name=&quot;jboss.entity.manager.factory.jndi.name&quot; value=&quot;java:/blogEntityManagerFactory&quot;/&gt;
      &lt;/properties&gt;
   &lt;/persistence-unit&gt;</pre>
<p>Here we defined the data-source as java:comp/env/jdbc/seamblog  for Tomcat requires all connection JNDI names to be prefixed with <strong>java:comp/env</strong>.</p>
<p>Finally we will modify the <strong>components.xml</strong> which holds the definition of certain Seam components and resides in WEB-INF folder.</p>
<p>There are a few things to do in components.xml</p>
<p>First add an XML namespace definition for transaction:</p>
<pre>xmlns:transaction=&quot;http://jboss.com/products/seam/transaction&quot;</pre>
<p>and its</p>
<pre> xsi:schemaLocation = http://jboss.com/products/seam/transaction http://jboss.com/products/seam/transaction-2.2.xsd</pre>
<p>then add the following line somewhere:</p>
<pre>&lt;transaction:entity-transaction entity-manager=&quot;#{entityManager}&quot;/&gt;</pre>
<p>Also the persistence-related definitions should be something like:</p>
<pre>   &lt;!-- If you are using Tomcat, you need the following to have your PU started --&gt;
  &lt;persistence:entity-manager-factory name=&quot;entityManagerFactory&quot;
                     persistence-unit-name=&quot;seamblogPU&quot;/&gt;
   &lt;!-- If you are using Tomcat, you need the following as well to have the entityManagerFactory used --&gt;
  &lt;persistence:managed-persistence-context name=&quot;entityManager&quot; auto-create=&quot;true&quot;
                         entity-manager-factory=&quot;#{entityManagerFactory}&quot;/&gt;

   &lt;!-- If you are not using JBoss AS 5 or above, the following should be commented --&gt;
&lt;!--    &lt;persistence:managed-persistence-context name=&quot;entityManager&quot; auto-create=&quot;true&quot; --&gt;
&lt;!--                            persistence-unit-jndi-name=&quot;java:/blogEntityManagerFactory&quot;/&gt; --&gt;</pre>
<p>Least but not last, open up your web.xml and add the following:</p>
<pre>&lt;resource-ref&gt;
        &lt;res-ref-name&gt;jdbc/seamblog&lt;/res-ref-name&gt;
        &lt;res-type&gt;javax.sql.DataSource&lt;/res-type&gt;
        &lt;res-auth&gt;Container&lt;/res-auth&gt;
 &lt;/resource-ref&gt;</pre>
<h3><span id="Running_the_Seam_Blog_Project_for_the_first_time">Running the Seam Blog Project for the first time</span></h3>
<p>Now let&#8217;s run the project and see what we&#8217;ve done.</p>
<p>Right-click the project name and select <strong>Run As &gt; Run on Server</strong> from the pop-up menu. Remember to choose Tomcat for target server.</p>
<p>If you&#8217;ve done everything correctly or at least as instructed in this tutorial, you should be welcomed with Seam&#8217;s cute welcome page thanks to its default template as shown in figure 3.7.</p>
<div id="attachment_182" class="wp-caption alignnone" style="width: 666px"><a href="http://gokhan.ozar.net/wp-content/uploads/seamProjDeployed.png"><img class=" wp-image-182 " title="seamProjDeployed" src="http://gokhan.ozar.net/wp-content/uploads/seamProjDeployed.png" alt="Seam Project Successfully Deployed" width="656" height="634" /></a><p class="wp-caption-text">Figure 3.7 - The Successfully Deployed Seam Blog Project</p></div>
<p>You can customize the welcome page by modifying <strong>home.xhtml</strong> at the root of the web content folder.<br />
Now let&#8217;s test our new app a little: Go to the menu bar of Seam Blog and click <strong>Browse data</strong> to pull down a menu from which I want you to select &#8216;Category List&#8217;. Here we will encounter a blank categories list. Click &#8216;Create Category&#8217; and after a possible user authentication which you may pass just by entering &#8216;admin&#8217; as the username and leaving the password blank (we haven&#8217;t programmed the user authentication yet), you should then encounter a form like the one in figure 3.8:</p>
<div id="attachment_183" class="wp-caption alignnone" style="width: 658px"><a href="http://gokhan.ozar.net/wp-content/uploads/seamProjNewCategory.png"><img class="size-full wp-image-183" title="seamProjNewCategory" src="http://gokhan.ozar.net/wp-content/uploads/seamProjNewCategory.png" alt="Creating a new category for the blog" width="648" height="505" /></a><p class="wp-caption-text">Figure 3.8 - Creating a new category for the blog</p></div>
<p>I created my first category as &#8216;General&#8217; and hit &#8216;Save&#8217;. Then I&#8217;ll repeat the step to create a few more categories such as &#8216;IT&#8217;, &#8216;Internet&#8217;, &#8216;Movies&#8217; and &#8216;Music&#8217;.</p>
<div id="attachment_184" class="wp-caption alignnone" style="width: 651px"><a href="http://gokhan.ozar.net/wp-content/uploads/seamProjCategoryListFilledUp.png"><img class="size-full wp-image-184" title="seamProjCategoryListFilledUp" src="http://gokhan.ozar.net/wp-content/uploads/seamProjCategoryListFilledUp.png" alt="Category list filled up" width="641" height="622" /></a><p class="wp-caption-text">Figure 3.9 - Seam Blog category list filled up</p></div>
<p>Finally I&#8217;ll go to Users section, to create the blog&#8217;s first user: Me!</p>
<div id="attachment_185" class="wp-caption alignnone" style="width: 642px"><a href="http://gokhan.ozar.net/wp-content/uploads/seamProjNewUser-go.png"><img class="size-full wp-image-185" title="seamProjNewUser-go" src="http://gokhan.ozar.net/wp-content/uploads/seamProjNewUser-go.png" alt="Creating blog users" width="632" height="612" /></a><p class="wp-caption-text">Figure 3.10 - Creating blog&#39;s users</p></div>
<p>The user entry page signals us that the form needs our help with certain aspects such as converting the password field into a real password field hiding the entered characters &#8211; i.e. JSF-wise an &lt;h:inputSecret /&gt; and the level field seems to make no sense there and should be worked on.</p>
<p>You could also choose to experiment with the post entry form which I saved for last, <em>but not as best</em>, yet you will probably find out how peculiar it is to select a category and a user from a grid on a separate screen instead of a pop-up menu when entering a blog post &#8211; assuming of course you did not get a <em>&#8220;duplicate Id for a component selectParent&#8221;</em> error which arises due to a <strong>Seam-gen 2.2 bug</strong> when the generated page of a given entity has more than one other object association &#8211; in our case the <strong>Post</strong> entity has <em>Many-to-One</em> associations of the <strong>Category</strong> and <strong>User</strong> entities respectively.</p>
<p>Our project has now some basic CRUD functionality and runs on Tomcat. <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part IV" href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-4/">In <strong>Part IV</strong> of the <strong>tutorial</strong></a>, we will customize the code, correct the buggy code Seam-gen gave us, and add some of our own code, all in JSF.</p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-3/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud &#8211; Part II</title>
		<link>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-2/</link>
		<comments>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-2/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 22:05:25 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JBoss Seam]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[JBoss Tools]]></category>
		<category><![CDATA[Tomcat]]></category>
		<category><![CDATA[tutorial]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=129</guid>
		<description><![CDATA[In part I of the tutorial, I provided the instructions about the development environment and  how to create the blog&#8217;s database. In this part II, using Eclipse&#8217;s JBoss tools plugin, we&#8217;ll create and configure the JBoss Seam web project and prepare &#8230; <a href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-153" title="seam-blog-tomcat-part2" src="http://gokhan.ozar.net/wp-content/uploads/seam-blog-tomcat-part2.jpg" alt="JBoss Seam - Tomcat" width="600" height="255" /></p>
<p>In <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part I" href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part1/"><strong>part I</strong></a> of the tutorial, I provided the instructions about the development environment and  how to create the blog&#8217;s database. In this <strong>part II</strong>, using Eclipse&#8217;s JBoss tools plugin, we&#8217;ll create and configure the <strong>JBoss Seam</strong> web project and prepare it for full <strong>Tomcat</strong>-compatibilty and for the creation the basic CRUD (create, read, update and delete) functionality of entities which will be reverse engineered from the database using <em>hbm2java</em> embedded in <em>Seam-gen </em>whose GUI version comes built-in with JBoss Tools<em>.</em></p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<h2>The Development Environment</h2>
<p>To be able to follow the tutorial and reproduce the same results, it&#8217;s best (if not mandatory) that you have exactly the same version of the tools and plug-ins I mentioned in the <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part I" href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part1/">previous post</a>. As of this part (and so on) I&#8217;ll instruct on <strong>Eclipse Helios</strong> with <strong>JBoss Tools 3.2</strong>. You can also refer to my post titled &#8216;<a title="Matrix of compatible platforms and runtimes with JBoss Tools" href="http://gokhan.ozar.net/matrix-of-supported-platforms-for-jboss-tools/">Matrix of compatible platforms and runtimes with JBoss Tools</a>&#8216; to see which version of Eclipse and other stuff (such as Seam framework version) is compatible with which version of JBoss tools plugin, etc.</p>
<p>So here we go. Now launch <strong>Eclipse</strong> if you already haven&#8217;t done so.</p>
<div id="attachment_132" class="wp-caption alignnone" style="width: 1034px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-open-perspective-other1.png"><img class="size-full wp-image-132" title="eclipse-open-perspective-other" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-open-perspective-other1.png" alt="Changing perspective in Eclipse" width="1024" height="767" /></a><p class="wp-caption-text">Figure 2.1 - Changing perspective in Eclipse</p></div>
<p>First of all, we shall change the perspective in Eclipse to Seam &#8211; that option, however, is only available if you have JBoss tools installed. See figure 2.1 and 2.2.<br />
<span id="more-129"></span><span style="color: #ff0000;"></span></p>
<div id="attachment_131" class="wp-caption alignnone" style="width: 369px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-select-seam-perspective.png"><img class="size-full wp-image-131" title="eclipse-select-seam-perspective" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-select-seam-perspective.png" alt="Switching to the Seam perspective in Eclipse" width="359" height="436" /></a><p class="wp-caption-text">Figure 2.2 - Switching to the Seam perspective in Eclipse</p></div>
<p>Now since we need to define a server runtime &#8211; in this case <strong>Apache Tomcat</strong>, go to the Servers tab on the bottom pane, right click the empty area and select New &gt; Server as shown in figure 2.3.</p>
<div id="attachment_133" class="wp-caption alignnone" style="width: 1033px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-server.png"><img class="size-full wp-image-133" title="eclipse-new-server" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-server.png" alt="Defining a new server in Eclipse" width="1023" height="768" /></a><p class="wp-caption-text">Figure 2.3 - Defining a new server in Eclipse</p></div>
<p>Then in the window which opens, specify the server as Apache Tomcat 6 as shown in figure 2.4.</p>
<div id="attachment_134" class="wp-caption alignnone" style="width: 528px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-server-tomcat6.png"><img class="size-full wp-image-134" title="eclipse-new-server-tomcat6" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-server-tomcat6.png" alt="Adding Tomcat 6 as the web server in Eclipse workspace" width="518" height="584" /></a><p class="wp-caption-text">Figure 2.4 - Adding Tomcat 6 as the web server in Eclipse workspace</p></div>
<p>As you select <em>Tomcat v6.0 server</em> from the <em>Apache</em> category in the list box, server&#8217;s host name will automatically be set to <em><strong>localhost</strong></em> as well as server name field being set to <em><strong>Tomcat v6.0 Server at localhost</strong></em> which are descriptive and good enough, therefore we&#8217;ll leave the rest as it is and click <em>next</em>, then <em>finish</em>.</p>
<h2>Creating the Seam project for Tomcat and MySQL</h2>
<p>Now we&#8217;re ready to create our <em>Seam</em> project. From the File menu on Eclipse&#8217;s main menu bar select <strong>New &gt; Seam Web Project</strong> as shown in figure 2.5. (Last reminder: this option only available if you have JBoss Tools installed, otherwise see the beginning of this post)</p>
<div id="attachment_136" class="wp-caption alignnone" style="width: 881px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj.png"><img class=" wp-image-136 " title="eclipse-new-seam-web-proj" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj.png" alt="Creating a new Seam web project in Eclipse" width="871" height="629" /></a><p class="wp-caption-text">Figure 2.5 - Creating a new Seam web project in Eclipse</p></div>
<p>Now we need to specify the settings and configuration for our new <em>Seam</em> web project which is a blog (CMS).</p>
<div id="attachment_137" class="wp-caption alignright" style="width: 535px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog.png" target="_blank"><img class=" wp-image-137 " title="eclipse-new-seam-web-proj-blog" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog.png" alt="Specifying configuration of a new Seam web project in Eclipse" width="525" height="697" /></a><p class="wp-caption-text">Figure 2.6 - Specifying configuration of a new Seam web project in Eclipse</p></div>
<p>Referring to figure 2.6, you can make the following settings.</p>
<ul>
<li>Project name: <strong>blog</strong></li>
<li>Target runtime: <strong>Apache Tomcat 6.0</strong></li>
<li>Dynamic web module version: <strong>2.5</strong></li>
<li>Target Server: <strong>Tomcat v6.0</strong> server at localhost</li>
<li>Configuration: <strong>Dynamic Web Project with Seam 2.2</strong></li>
</ul>
<p>Click <em>Next</em> <strong>twice</strong> and you will get something like in figure 2.7:</p>
<div id="attachment_138" class="wp-caption alignnone" style="width: 932px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog2.png"><img class=" wp-image-138" title="eclipse-new-seam-web-proj-blog2" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog2.png" alt="Specifying JSF implementation library for the Seam project" width="922" height="730" /></a><p class="wp-caption-text">Figure 2.7 - Specifying JSF implementation library for the Seam project</p></div>
<p>In this screen (as shown in figure 2.7), we need to specify the <em>JSF implementation</em> library which is to be <em><strong>Mojarra 1.2</strong></em>. If we had chosen a <strong>JBoss Application Server</strong> for deployment, we would have had the possibility of using the libraries bundled with the JBoss runtime. Since we&#8217;ll deploy to Tomcat we need to go with the <strong><em>user library option</em></strong> which we need to provide ourselves. So click the tiny &#8216;manage libraries&#8217; button and click &#8216;New..&#8217; in the new window which opens. Here, I named the new user library as GO-JSF. You can name yours whatever you want as this is a one-time thing.</p>
<div id="attachment_139" class="wp-caption alignnone" style="width: 915px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog3-new-user-lib.png"><img class="size-full wp-image-139" title="eclipse-new-seam-web-proj-blog3-new-user-lib" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog3-new-user-lib.png" alt="eclipse-new-seam-web-proj-blog3-new-user-lib" width="905" height="726" /></a><p class="wp-caption-text">Figure 2.8 - Adding JSF libraries to the Seam project manually</p></div>
<p>Now after you provide the name for the new user library intended for our JSF jars, we we need to put them in there. Make sure you have downloaded Mojarra 1.2 jars or my bundle called GO-JSF and have them somewhere accessible and ready (as separate jar files) on your computer.</p>
<div id="attachment_140" class="wp-caption alignright" style="width: 675px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog4-go-jsf-add-jars.png"><img class="size-full wp-image-140" title="eclipse-new-seam-web-proj-blog4-go-jsf-add-jars" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog4-go-jsf-add-jars.png" alt="Adding JSF 1.2  jar files to user-defined library in Eclipse" width="665" height="676" /></a><p class="wp-caption-text">Figure 2.9 - Adding JSF 1.2 jar files to user-defined library in Eclipse</p></div>
<p>Refer to figure 2.9 for a complete list of JSF jar files to our custom library and namely they are:</p>
<ul>
<li>jsf-api.jar</li>
<li>jsf-facelets.jar</li>
<li>jsf-impl.jar</li>
<li>jsf-tlds.jar</li>
<li>jstl.jar</li>
</ul>
<p>Click OK and then make sure the user JSF library&#8217;s checkbox is checked as well as an option saying &#8220;include libraries with this application&#8221;. The remaining settings regarding JSF in this screen should be as good as defaults, so you can click &#8216;next&#8217; if what&#8217;s on your screen resembles figure 2.10 (otherwise make your settings similar to it).</p>
<div id="attachment_141" class="wp-caption alignright" style="width: 535px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog5-go-jsf-selected.png"><img class="size-full wp-image-141" title="eclipse-new-seam-web-proj-blog5-go-jsf-selected" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog5-go-jsf-selected.png" alt="JSF settings of Seam web project in Eclipse" width="525" height="697" /></a><p class="wp-caption-text">Figure 2.10 - JSF settings of Seam web project in Eclipse</p></div>
<p>On the next screen we need to specify the Seam runtime and a database connection profile for ORM. If you&#8217;re making a Seam development for the first time with the IDE, the Seam runtime selection pop-up menu will probably be blank in which case we need to add one. We want Seam 2.2.2, so if it is not present as an option we need to &#8216;add&#8217; it.</p>
<div id="attachment_142" class="wp-caption alignnone" style="width: 535px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog6.png"><img class="size-full wp-image-142" title="eclipse-new-seam-web-proj-blog6" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog6.png" alt="Configuring Seam facet" width="525" height="697" /></a><p class="wp-caption-text">Figure 2.11 - Configuring Seam facet in Eclipse</p></div>
<p>After clicking &#8216;Add&#8217; (assuming you needed to), you should click browse in the pop-up window, to specify the location of the Seam framework folder you have (downloaded) on your hard-drive. Make sure it&#8217;s version 2.2(.2) and click Finish.</p>
<div id="attachment_143" class="wp-caption alignnone" style="width: 535px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog7-new-seam-runtime.png"><img class="size-full wp-image-143" title="eclipse-new-seam-web-proj-blog7-new-seam-runtime" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog7-new-seam-runtime.png" alt="Specifying Seam 2.2.2 final as the Seam runtime" width="525" height="307" /></a><p class="wp-caption-text">Figure 2.12 - Specifying Seam 2.2.2 final as the Seam runtime</p></div>
<p>Finally we can enter the database settings. Select MySQL (InnoDB) for database type and click &#8216;New&#8217; or &#8216;Edit&#8217; depending on whether you&#8217;re doing this for the first time in the given workspace or not.</p>
<div id="attachment_144" class="wp-caption alignnone" style="width: 535px"><img class="size-full wp-image-144" title="eclipse-new-seam-web-proj-blog8-database-type" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog8-database-type.png" alt="Configuring database connection profile in Seam" width="525" height="697" /><p class="wp-caption-text">Figure 2.13 - Configuring database connection profile in Seam</p></div>
<p>Figure 2.14 demonstrates how to configure the database settings in detail:</p>
<div id="attachment_145" class="wp-caption alignleft" style="width: 258px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog10-conn-profile-mysql.png"><img class="size-medium wp-image-145 " title="eclipse-new-seam-web-proj-blog10-conn-profile-mysql" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog10-conn-profile-mysql-248x300.png" alt="Configuring MySQL connection profile for Seam project (1)" width="248" height="300" /></a><p class="wp-caption-text">Figure 2.14 - Configuring MySQL connection profile for Seam project (1)</p></div>
<div id="attachment_146" class="wp-caption alignleft" style="width: 535px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog11-conn-profile-mysql-driver.png"><img class="size-full wp-image-146" title="eclipse-new-seam-web-proj-blog11-conn-profile-mysql-driver" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog11-conn-profile-mysql-driver.png" alt="Configuring MySQL driver for Seam project in connection profile" width="525" height="657" /></a><p class="wp-caption-text">Figure 2.15 - Configuring MySQL connection profile for Seam project (1)</p></div>
<p>When you reach to the next screen, you will need to specify the version and location of the MySQL JDBC driver library (.jar) if you&#8217;ve never done this before in the current workspace.</p>
<p>You&#8217;ll know what to do if the drop-down list is blank or you don&#8217;t see an item indicating that MySQL 5.1 JDBC driver is installed. (See figure 2.15) Just click the tiny button next to it on the right and then refer to figure 2.16.</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="attachment_147" class="wp-caption alignnone" style="width: 310px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog12-conn-profile-mysql-driver-51.png"><img class="size-medium wp-image-147" title="eclipse-new-seam-web-proj-blog12-conn-profile-mysql-driver-51" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog12-conn-profile-mysql-driver-51-300x250.png" alt="Selecting MySQL JDBC Driver 5.1" width="300" height="250" /></a><p class="wp-caption-text">Figure 2.16 - Selecting MySQL JDBC Driver 5.1 for Seam project</p></div>
<p>Switch to the Jar List tab in the New Driver Definition window to put in the appropriate MySQL JDBC jar, otherwise the OK button won&#8217;t even be active to save the settings and close the window.</p>
<div id="attachment_148" class="wp-caption alignleft" style="width: 310px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog13-conn-profile-mysql-driver-51-editjar.png"><img class="size-medium wp-image-148" title="eclipse-new-seam-web-proj-blog13-conn-profile-mysql-driver-51-editjar" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog13-conn-profile-mysql-driver-51-editjar-300x250.png" alt="Editing the JAR location" width="300" height="250" /></a><p class="wp-caption-text">Figure 2.17 - Editing the JAR location</p></div>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<div id="attachment_149" class="wp-caption alignnone" style="width: 310px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog14-conn-profile-select-mysql-driver.png"><img class="size-medium wp-image-149 " title="eclipse-new-seam-web-proj-blog14-conn-profile-select-mysql-driver" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog14-conn-profile-select-mysql-driver-300x171.png" alt="Indicating the file path of MySQL JDBC driver library (jar) " width="300" height="171" /></a><p class="wp-caption-text">Figure 2.18 - Indicating the file path of MySQL JDBC driver library (jar)</p></div>
<div id="attachment_151" class="wp-caption alignnone" style="width: 899px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog16-conn-profile-ping-succeeded.png"><img class=" wp-image-151 " title="eclipse-new-seam-web-proj-blog16-conn-profile-ping-succeeded" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog16-conn-profile-ping-succeeded.png" alt="Database Connection details" width="889" height="718" /></a><p class="wp-caption-text">Figure 2.19 - Seam database connection details</p></div>
<p>After you specify the location of the jars, you can specify the connection details as shown in figure 2.19 and finalize the settings. Also click the Test connection button to see if you have configured everything properly. If the ping fails, repeat the steps to create a connection profile and defining the JDBC driver.</p>
<p>As soon as the connection settings are OK, we will lastly specify the model and the controller package names under the source code generation section. Session bean package name refers to the <em><strong>controller</strong></em> although we won&#8217;t use any EJB here since we&#8217;re sticking with Tomcat.</p>
<p>Enter <strong>net.ozar.blog.session</strong> for the controller package name, and <strong>net.ozar.blog.entity</strong> for the entity bean package name, and then click the <em>Finish</em> button to finalize the creation steps of the Seam web project, in this case the blog.</p>
<div id="attachment_152" class="wp-caption alignnone" style="width: 910px"><a href="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog17-finish.png"><img class=" wp-image-152" title="eclipse-new-seam-web-proj-blog17-finish" src="http://gokhan.ozar.net/wp-content/uploads/eclipse-new-seam-web-proj-blog17-finish.png" alt="Finalize Seam web project creation" width="900" height="730" /></a><p class="wp-caption-text">Figure 2.20 - Finalizing Seam web project creation</p></div>
<p>In <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part III" href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-3/"><strong>part III</strong> of the tutorial</a>, we will create the model layer and some basic controller code (for CRUD operations)  and then modify the project&#8217;s configuration so as to make it Tomcat-compatible.</p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud &#8211; Part I</title>
		<link>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-1/</link>
		<comments>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-1/#comments</comments>
		<pubDate>Sun, 22 Jan 2012 19:38:03 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JPA]]></category>
		<category><![CDATA[MySQL]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Facelets]]></category>
		<category><![CDATA[JBoss Seam]]></category>
		<category><![CDATA[RichFaces]]></category>
		<category><![CDATA[Tomcat]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=91</guid>
		<description><![CDATA[Tired of simple hello world tutorials or tutorials taking you only as far as user login and registration examples? Here&#8217;s an intermediate-level tutorial in which I will demonstrate how to make a blog CMS application using JBoss Seam incorporating JSF (w/Facelets), &#8230; <a href="http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-1/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>Tired of <strong>simple</strong> <em>hello world</em> tutorials or tutorials taking you only as far as <em>user login</em> and <em>registration examples</em>? Here&#8217;s an <strong>intermediate-level tutorial</strong> in which I will demonstrate how to make a <strong>blog</strong> CMS application using <em><strong>JBoss Seam</strong></em> incorporating<em> <strong>JSF</strong></em> (w/<em>Facelets)</em>, <em>Hibernate JPA</em> and how to deploy it to <strong><em>Apache Tomcat</em></strong> web server. With this tutorial, I also aim to provide complete and correct instructions for preparing a Seam 2.2 project to be deployed on Tomcat <strong>without errors</strong>.</p>
<p><img class=" wp-image-156 alignnone" title="seam-blog-tomcat" src="http://gokhan.ozar.net/wp-content/uploads/seam-blog-tomcat1.jpg" alt="JBoss Seam Project on Tomcat" width="600" height="255" /></p>
<p>The blog we&#8217;ll make in this tutorial is simple, but the tutorial itself is not.</p>
<p>Here&#8217;s a list of technologies and frameworks with their versions which we will use here:</p>
<ul>
<li><strong>Java EE 5</strong> (on JRE 6)</li>
<li><strong>JBoss Seam 2.2.2</strong> (incorporating JSF 1.2 + Facelets, RichFaces 3.3.3 and Hibernate JPA 1.0)</li>
<li><strong>Apache Tomcat 6</strong>.0</li>
<li><strong>MySQL 5.1</strong> (community edition)</li>
</ul>
<p>And the tools we will use such as the IDE and the database GUI administartion tool:</p>
<ul>
<li><a title="Eclipse Packages" href="http://www.eclipse.org/downloads/packages/release/helios/r" target="_blank"><strong>Eclipse</strong> Helios</a> for Java EE developers</li>
<li><a title="JBoss Tools | Downloads - JBoss Community" href="http://www.jboss.org/tools/download" target="_blank">JBoss Tools 3.2</a></li>
<li><a title="Find the best MySQL, PostgreSQL and Oracle administration and development software you're looking for at navicat.com, the most popular MySQL, PostgreSQL and Oracle Admin tool for database management. Includes import/export wizard, support unicode, support foreign keys, schedule backup, data transfer, reporting, visual query builder, SSH, HTTP, code completion and more useful features." href="http://www.navicat.com/en/products/navicat_premium/premium_overview.html" target="_blank">PremiumSoft <strong>Navicat</strong></a> 9.07</li>
</ul>
<p><span id="more-91"></span></p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>Make sure you get the tools above or some equivalent so that you can follow me as I go along the tutorial. Although <em><strong>Seam</strong></em> development with <strong>JBoss Tools</strong> makes it easy to incorporate the necessary libraries (jars) into your project, in case of Tomcat development you will need to bring along your own set of JSF libraries &#8211; for the sake of the tuorial and making life easier I created a bundle of the necessary jar files in a zip file which you could download from <a title="Downloads | All Systems GO" href="http://gokhan.ozar.net/downloads/?did=2">here</a>.</p>
<p><span style="color: #ff0000;"></span></p>
<h2>Creating the Blog Database</h2>
<p>Assuming you already have a MySQL 5.1 database server installed and running, we will create the blog database on MySQL using Navicat and then the necessary tables.</p>
<div id="attachment_110" class="wp-caption alignnone" style="width: 594px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-create-new-db.png"><img class=" wp-image-110" title="navicat-create-new-db" src="http://gokhan.ozar.net/wp-content/uploads/navicat-create-new-db-1024x784.png" alt="Creating a new database in Navicat" width="584" height="447" /></a><p class="wp-caption-text">Figure 1.1</p></div>
<p>In Navicat, having your localhost defined and connected to, right-click localhost and select &#8216;Create new database&#8230;&#8217; and then you should be presented with a dialog box as shown in figure 1.1 asking you to specify the database name and select a character set from a drop-down menu.</p>
<p>Enter<em> &#8220;seamblog&#8221;</em> (without quotes) and select UTF-8 (unicode) from the pull-down menu below, then click OK. (Optionally you can specify a collation matching that of your language if it is anything different than English.</p>
<div id="attachment_112" class="wp-caption alignnone" style="width: 787px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-create-blogger-user-with-pw-123451.png"><img class=" wp-image-112" title="navicat-create-blogger-user-with-pw-12345" src="http://gokhan.ozar.net/wp-content/uploads/navicat-create-blogger-user-with-pw-123451.png" alt="create the database user in Navicat" width="777" height="559" /></a><p class="wp-caption-text">Figure 1.2 - Manage Users</p></div>
<p>Then click &#8216;Manage users&#8217; the big button with a <em>user</em> icon on the toolbar of Navicat&#8217;s main window whileyour newly created database is selected. Alternatively you can right-click &#8216;seamblog&#8217; from the databases list and select &#8216;Manage Users&#8230;&#8217; from the pop-up menu.</p>
<p>Name the user <em>&#8216;blogger&#8217;</em>, the host <em>localhost</em> and enter &#8217;12345&#8242; as the password then click OK.</p>
<div id="attachment_114" class="wp-caption alignnone" style="width: 786px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-granting-priveleges-to-blogger-4-seamblog.png"><img class="size-full wp-image-114" title="navicat-granting-priveleges-to-blogger-4-seamblog" src="http://gokhan.ozar.net/wp-content/uploads/navicat-granting-priveleges-to-blogger-4-seamblog.png" alt="Granting blog priveleges to the blogger user in Navicat" width="776" height="353" /></a><p class="wp-caption-text">Figure 1.3 - Granting Seam blog priveleges to the blogger user in Navicat</p></div>
<p>Click the tiny triangle (bullet) preceding the <em><strong>blogger</strong>@localhost</em> user to display the database list, and select <em><strong>seamblog</strong></em> from the list, then <strong><em>Select All</em></strong> the priveleges on the right pane of the window as shown in figure 1.3. Finally click &#8216;save&#8217;.</p>
<p>Now it&#8217;s time we created the necessary tables.</p>
<div id="attachment_115" class="wp-caption alignnone" style="width: 977px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-creating-the-category-table.png"><img class="size-full wp-image-115" title="navicat-creating-the-category-table" src="http://gokhan.ozar.net/wp-content/uploads/navicat-creating-the-category-table.png" alt="Creating a table in Navicat" width="967" height="612" /></a><p class="wp-caption-text">Figure 1.4 - Creating the &#39;category&#39; table in Navicat</p></div>
<p>Click &#8216;New Table&#8217; from the the Navicat toolbar, then create three fields named &#8216;id&#8217; (smallint, primary key, auto-incrementing), &#8216;name&#8217; (varchar, 31 characters length) and version (smallint, with null values allowed) respectively. Then save the table with the name &#8216;category&#8217;. It&#8217;s easy with Navicat&#8217;s intuitive graphic user interface. An SQL dump of the database is also included at the end of the database section of the tutorial.</p>
<p>As the name suggests, this table is where the categories of blog posts will be kept. Now onto the <em>&#8216;user&#8217;</em> table:</p>
<div id="attachment_116" class="wp-caption alignright" style="width: 1044px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-creating-the-user-table.png"><img class="size-full wp-image-116" title="navicat-creating-the-user-table" src="http://gokhan.ozar.net/wp-content/uploads/navicat-creating-the-user-table.png" alt="Creating the blog users table in Navicat" width="1034" height="788" /></a><p class="wp-caption-text">Figure 1.5 - Creating the blog&#39;s &#39;user&#39; table in Navicat</p></div>
<p>Create the user table with the following fields as shown in figure 1.5:</p>
<ul>
<li>id (mediumint, allow null, primary key with auto-increment)</li>
<li>name (varchar 50)</li>
<li>login (varchar 12)</li>
<li>password (varchar 40, allow null)</li>
<li>email (varchar 50)</li>
<li>level (tinyint)</li>
</ul>
<p>And finally the table for posts:</p>
<div id="attachment_117" class="wp-caption alignright" style="width: 786px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-creating-the-post-table.png"><img class="size-full wp-image-117" title="navicat-creating-the-post-table" src="http://gokhan.ozar.net/wp-content/uploads/navicat-creating-the-post-table.png" alt="Creating a table for Seam Blog's posts in Navicat" width="776" height="599" /></a><p class="wp-caption-text">Figure 1.6 - Creating the &#39;post&#39; table in Navicat</p></div>
<p>For this one we need the following fields as shown in figure 1.6:</p>
<ul>
<li>id (int, auto-incrementing primary key)</li>
<li>user_id (mediumint, null values allowed)</li>
<li>category_id (smallint)</li>
<li>title (varchar 200)</li>
<li>content (longtext)</li>
<li>post_date (datetime)</li>
<li>version (smallint, allowing null values)</li>
</ul>
<p>Now that&#8217;s it for creation of the tables. Next, we will define some foreign-key restraints. This is absolutely necessary for mapping the many-to-one and one-to-many relationships between the JPA entities.</p>
<div id="attachment_118" class="wp-caption alignnone" style="width: 594px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-defining-fk_post_4_user.png"><img class=" wp-image-118 " title="navicat-defining-fk_post_4_user" src="http://gokhan.ozar.net/wp-content/uploads/navicat-defining-fk_post_4_user-1024x779.png" alt="Defining a foreign key between post and user in Navicat" width="584" height="444" /></a><p class="wp-caption-text">Figure 1.7 - Defining a many-to-one relationship between post and user in Navicat</p></div>
<p>Now right-click the <em><strong>post</strong></em> table from the tables list and select <em><strong>&#8216;Design table&#8217;</strong></em> from the pop-up menu. In the table design window, switch to the &#8216;<strong>Foreign Keys</strong>&#8216; tab. Then click &#8216;<strong>Add foreign key</strong>&#8216; button on the toolbar.</p>
<p>Name the foreign key &#8216;fk_post_4_user&#8217;, choose <strong>user_id</strong> for field name(s), <em>seamblog</em> for reference database, <em><strong>user</strong></em> for reference table, and check <em><strong>&#8216;id&#8217;</strong></em> from the pop-up menu under &#8216;Foreign Field Names&#8217; as shown in figure 1.7. Select <em><strong>cascade</strong></em> <em>on delete</em>, and <em><strong>restrict</strong></em> on <em>update</em>.</p>
<p>What this FK definition means is that for a <em>post</em> we have many <em>users</em> to choose from, and a user can have many posts.</p>
<p>Now we need one last foreign key for defining a many-to-one relationship between post and categories, so that a post can have one category to choose from a list of many categories, but a single category can have many posts.</p>
<p>Refer to figure 1.8 for creating the foreign key named &#8220;fk_post_4_category&#8217;.</p>
<div id="attachment_119" class="wp-caption alignright" style="width: 815px"><a href="http://gokhan.ozar.net/wp-content/uploads/navicat-defining-fk_post_4_category.png"><img class=" wp-image-119" title="navicat-defining-fk_post_4_category" src="http://gokhan.ozar.net/wp-content/uploads/navicat-defining-fk_post_4_category.png" alt="Defining a foreign key in Navicat" width="805" height="412" /></a><p class="wp-caption-text">Figure 1.8 - Defining a foreign key between post and category in Navicat</p></div>
<p>That&#8217;s it for the database which I want to keep simple for the time being.</p>
<p>In <a title="Create a Blog with JBoss Seam, Hibernate JPA and JSF then Deploy it to Tomcat in the Cloud – Part II" href="http://gokhan.ozar.net/create-a-blog-with-jboss-seam-hibernate-jpa-and-jsf-then-deploy-it-to-tomcat-in-the-cloud-part-ii/">Part II</a>, I&#8217;ll show you how to create the <em>Seam</em> project and the database connection settings and in Part III the creation of the model layer by reverse engineering this very database, so it is important that you carefully follow the instructions here for creating the seamblog database.</p>
<p>You can download the database dump file in .sql format in the downloads section (which has some sample data in it &#8211; posts and categories entered with the finished version of the blog)</p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/blog-with-jboss-seam-on-tomcat-in-the-cloud-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Best 5 Java web application frameworks</title>
		<link>http://gokhan.ozar.net/best-java-web-frameworks/</link>
		<comments>http://gokhan.ozar.net/best-java-web-frameworks/#comments</comments>
		<pubDate>Thu, 24 Nov 2011 12:14:18 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Java EE]]></category>
		<category><![CDATA[JBoss Seam]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[web application development]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=38</guid>
		<description><![CDATA[When it comes to developing web applications using Java, writing all the code from scratch has its advantages if you&#8217;re trying to master a new technology, but for real life web applications, you have to go for a framework as many &#8230; <a href="http://gokhan.ozar.net/best-java-web-frameworks/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<div id="attachment_61" class="wp-caption alignright" style="width: 310px"><a href="http://gokhan.ozar.net/wp-content/uploads/jsf.jpg"><img class="size-medium wp-image-61 " title="Java Server Faces" src="http://gokhan.ozar.net/wp-content/uploads/jsf-300x154.jpg" alt="JSF" width="300" height="154" /></a><p class="wp-caption-text">Some programmers think JSF has a steep learning curve</p></div>
<p>When it comes to developing web applications using Java, writing all the code from scratch has its advantages if you&#8217;re trying to master a new technology, but for real life web applications, you have to go for a framework as many expert developers would agree. Otherwise you risk a great deal of failure because of having allocated too much time and too many resources by re-inventing the wheels.</p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<blockquote>
<p style="text-align: left;">There are some hardliners who still argue why there&#8217;s ever a need for a framework, since everything can be accomplished by Servlets, JSP and Filters. One of them is Bear Bibeault author of JQuery in Action.</p>
<p style="text-align: left;">-Adeel Ansari</p>
</blockquote>
<p>The cost is an important factor—although &#8220;free&#8221; in most cases also means widespread usage, community support, and no dependence on a single vendor. It takes some time for developers to get used to a framework and be good at it. Therefore choosing a framework as a long-term strategy. You cannot be switching frameworks for every project. Sticking with one framework also helps as once the expertise in that framework builds up; customizing the framework also becomes a possibility.</p>
<p>A tempting option is for organizations to build their own framework to address needs specific to the kind of work the organization undertakes. Although it does <del>seam</del> seem to make sense on paper, for my money, this is a suicidal strategy. Thoroughly testing and maintaining a framework is a huge task that will need dedicated human resources. These few people would become critical and the only source of support for others using that framework. Also, with so many quality frameworks available for free, I seriously doubt it really is necessary.</p>
<p>As with many web frameworks emerging nowadays, the ever-increasing number of Java web application frameworks out there today is intimidating for many developers even to look into because of being presented with too many choices. However, matching the criteria of popularity, widespread usage and tooling support, I can list a few of the best Java web application frameworks here and in a descending order of my personal choice. Sorry if I haven&#8217;t listed your favorite Java web framework here, feel free to agree or disagree in the comments section.<span id="more-38"></span></p>
<ol>
<li>Struts (2)</li>
<li>Wicket</li>
<li>Spring</li>
<li>JSF</li>
<li>Seam</li>
</ol>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<div id="toc_container" class="no_bullets"><p class="toc_title">Contents</p><ul class="toc_list"><li><a href="#Struts_2">1 Struts 2</a></li><li><a href="#Wicket">2 Wicket</a></li><li><a href="#Spring_MVC_and_Webflow">3 Spring MVC and Webflow</a></li><li><a href="#Java_Server_Faces">4 Java Server Faces</a></li><li><a href="#JBoss_Seam">5 JBoss Seam</a></li><li><a href="#Conclusion">6 Conclusion</a></li></ul></div>
<h3><span id="Struts_2">Struts 2</span></h3>
<p>Struts 1.x was the first most popular and widely accepted web framework for Java, because of the way it handled the MVC model 2 paradigm and its action-based architecture. It was an elegant framework that handled the flow of application and a lot of other routine tasks. Another advantage of using Struts was an incredibly growing number of developers preferred it as a de-facto J2EE standard. Many of the popular Java IDEs also provided tools for Struts development, making life even easier for the programmers. Even today IDEs like NetBeans and JBoss Developer Studio have built-in support for Struts 1.</p>
<p>Apache Struts 2 was originally known as WebWork 2 built on top of XWork, which provided a generic command pattern framework as well as an Inversion of Control container. After working independently for several years, the WebWork and Struts communities joined forces to create Struts2.</p>
<p>Programming the abstract classes instead of interfaces is one of design problem of Struts 1 framework that has been resolved in Struts2. Most of the Struts 2 classes are based on interfaces and most of its core interfaces are HTTP independent. Struts 2 Action classes are framework-independent and are simplified and they resemble POJOs. Framework components can easily be loosely coupled.</p>
<p>Struts 2 Actions are simple POJOs. Any java class with execute() method can be used as an Action class. With Struts 2 you don&#8217;t even have to implement interfaces. Inversion of Control is introduced while developing the action classes. This make the actions to be neutral to the underlying framework</p>
<p>ActionForms are also gone in Struts2. Simple JavaBean flavored actions are used to put properties directly. No need to use all String properties.</p>
<p>Biggest downfall of Struts 2 is poor documentation and no debugger feedback for missing properties or invalid OGNL expressions which makes debugging a nightmare.</p>
<h3><span id="Wicket">Wicket</span></h3>
<p>&#8220;With proper mark-up/logic separation, a POJO data model, and a refreshing lack of XML, Apache Wicket makes developing web-apps simple and enjoyable again&#8221; says the Apache Wicket Team in their description of this young and popular framework. &#8220;Swap the boilerplate, complex debugging and brittle code for powerful, reusable components written with plain Java and HTML&#8221;.</p>
<p>It&#8217;s a wide-spread Java web application framework mostly adopted by Struts old-timers and those who refuse to switch to JSF and Seam as far as what I observe.</p>
<p>Wicket strives for a clean separation between the roles of HTML page designer and Java developer by supporting plain HTML-based templates (which live next to Java code) that can be built using any WYSIWYG HTML design tools. The templates can then be made dynamic with little modification.</p>
<p>Like other frameworks, Wicket is built on top of Sun Microsystems&#8217; servlet API. However, unlike frameworks based on the Model-View-Controller (MVC) model (such as Struts), Wicket takes away from you the task of handling request/response objects, which is inherent with technologies such as servlets. By taking away this task, Wicket allows you to concentrate on the application&#8217;s business logic.</p>
<p>As a Wicket developer, you should think in terms of building reusable components that are stateful, instead of building controllers that handle request/response objects and worrying about multithreading issues. Instead of creating a controller or action class, you create a page, place components on it, and define how each component reacts to user input.</p>
<p>Wicket is great for Java developers, not especially for web developers. It requires a good grasp of objected-oriented programming as everything&#8217;s done almost in pure Java. It It has tight binding between pages and views and there&#8217;s an active community support including support from its creators.</p>
<h3><span id="Spring_MVC_and_Webflow">Spring MVC and Webflow</span></h3>
<p>Spring is the most popular application development framework for enterprise Java, that provides an incredibly powerful and flexible collection of technologies to improve your enterprise Java application development that is used by millions of developers.</p>
<p>Some of its advantages are:</p>
<ul>
<li>Lifecyle for overriding binding, validation, etc.</li>
<li>Integrates with many view options seamlessly: JSP/JSTL, Tiles, Velocity, FreeMarker, Excel, PDF</li>
<li>Inversion of Control makes it easy to test</li>
<li>Advanced security</li>
<li>Advanced support for Aspect-Oriented Programming (AOP)</li>
</ul>
<p>Many mission-critical Java enterprise applications are based on the Spring framework. Although you can integrate JSF (even Seam) with Spring, it lacks built-in JSF and AJAX support unlike JBoss Seam.</p>
<h3><span id="Java_Server_Faces">Java Server Faces</span></h3>
<p>Although JSF is not fairly a new framework, it&#8217;s become a Java EE standard (as of Java EE 5), developed through Java Community Process (JCP), that makes it easy to build user interfaces for java web applications by assembling reusable components in a page. Fast and easy to develop with initially, JSF comes with a plethora of ready to use components which you can quickly and easily reuse or add to many times in a page and capture events generated by actions on these components.</p>
<p>JSF is based on the well-established Model-View-Controller (MVC) design paradigm. Applications developed using JSF frameworks are forcibly well designed and usually easier to maintain than others.</p>
<p>Unlike action-based frameworks such as Struts and Spring, JSF applications are event-based. You typically embed components in a web page using custom tags defined by JSF technology and use the framework to handle navigation from one page to another.</p>
<p>JSF offers a flexible and extensible architecture that makes easy creating reusable, complex server side UI components without limiting developers to a particular mark-up language, protocol, or client device by combining the UI component functionality with custom renderers.</p>
<p>Some other advantages of using Java Server Faces are:</p>
<ul>
<li>JSF provides standard, reusable components for creating user interfaces for web applications.</li>
<li>JSF provides many tag libraries for accessing and manipulating the components.</li>
<li>It automatically saves the form data and repopulates the form when it is displayed at client side.</li>
<li>JSF encapsulates the event handling and component rendering logic from programmers, programmers just use the custom components.</li>
<li>There are many GUIs available these days to simplify the development of web based application based on JSF framework.</li>
</ul>
<p>See my other articles on JSF for more detailed information, tutorials and resources.</p>
<h3><span id="JBoss_Seam">JBoss Seam</span></h3>
<p>JBoss Seam is a framework that brings together existing Java Platform, Enterprise Edition (Java EE) standards to enable them to work as an integrated solution. At its core, the Seam framework ties the Enterprise JavaBeans 3 (EJB3) and JavaServer Faces (JSF) specifications. However, Seam does not just stop there—it will also join together other component models that you may be used to, such as Hibernate (for ORM), jBPM (for business process management and workflows), Drools (business rule management system), and more.</p>
<p>To be useful, your application has to be a multitiered application that uses specific components for the presentation, business, and persistence tiers. Before, you may have accomplished this with a combination of Struts (presentation), Spring (business), and Hibernate (persistence) frameworks. Now, following the Java EE specification, you will be using JSF (presentation), EJB3 session-beans (business), and EJB3 entity beans (persistence) with Seam. As before, each of these components requires lots of glue to link them together to talk to each other where Seam solves all of these.</p>
<p>EJB 2.1 had some negative connotations, especially regarding the way it relates to stateful session beans and entity beans. Thanks to the new EJB3 specification, EJBs have become lightweight plain old Java objects (POJOs) that do not require as much of the “plumbing” as before.</p>
<p>Seam has been designed from the ground up to eliminate complexity at both architecture and API levels. It enables developers to assemble complex web applications using simple annotated Java classes, a rich set of UI components, and very little XML. Seam&#8217;s unique support for conversations and declarative state management can introduce a more sophisticated user experience while at the same time eliminating common bugs found in traditional web applications.</p>
<p>Seam 2 introduces the concept of bijection, taken from Spring&#8217;s dependency injection feature where objects can be in-jected or out-jected to/from assigned variables using the @In and @Out annotations.</p>
<p>The framework also expands the concept of contexts. Each Seam component exists within a context. The default Seam context, a conversation, can span multiple pages and usually spans the whole business flow, from start to finish. The session context captures all actions of a user until he/she logs out or closes the browser &#8211; even across multiple uses of the browser back-button.</p>
<p>One can automatically generate a CRUD (create-read-update-delete) web-application from an existing database using the command-line tool seam-gen supplied with the framework.</p>
<p>Where there are holes in the specifications (for example, limitations in the JSF lifecycle for GET requests), Seam fixes them. And the authors of Seam are working with the JCP expert groups to make sure those fixes make their way back into the next revision of the standards.</p>
<p>Seam facilitates development through the use of JBoss Tools, a set of plug-ins targeted at the open-source Eclipse integrated development environment.<br />
Seam integrates out of the box with the RichFaces and ICEfaces Ajax libraries, as well as with many other Ajax libraries &#8211; without the need to write JavaScript code.</p>
<p>Seam also includes built-in libraries for creation of PDF documents, <em>Microsoft Excel</em> worksheets, graphs / charts (independent from Excel) and emailing them.</p>
<p>The possibility of integrating <strong>Seam</strong> with <strong>Spring</strong> might make it the ideal choice for developers who are also keen for making the switch to JSF.</p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<h3><span id="Conclusion">Conclusion</span></h3>
<p>Although <strong>Tapestry</strong> and <strong>Stripes</strong> might deserve a mention, I purposefully omitted them in this article as I don&#8217;t believe they&#8217;re in the top 5 java web frameworks. Tapestry with its HTML-based templates is almost as old as Struts, very productive once you learn, but with its scarcity of learning resources and steep learning curve, every adopter chooses &#8211; sooner or later &#8211; to switch to something else. As for Stripes which could deserve mentioning for its convention over configuration (no XML) and good documentation, has some major drawbacks such as the size of its community being too small, and it&#8217;s not actively developed as other projects.</p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/best-java-web-frameworks/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Matrix of compatible platforms and runtimes with JBoss Tools</title>
		<link>http://gokhan.ozar.net/matrix-of-supported-platforms-for-jboss-tools/</link>
		<comments>http://gokhan.ozar.net/matrix-of-supported-platforms-for-jboss-tools/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 15:57:32 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[Eclipse]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[JBoss Tools]]></category>
		<category><![CDATA[Seam]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=18</guid>
		<description><![CDATA[Use Eclipse with the JBoss Tools plugin instead of  JBoss Developer Studio? It can get somewhat tricky to get the right version of the tools plugin to work with the compatible version of Eclipse and the correct version of JSF &#8230; <a href="http://gokhan.ozar.net/matrix-of-supported-platforms-for-jboss-tools/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="size-full alignright" title="JBoss Tools Icon" src="http://gokhan.ozar.net/wp-content/uploads/20111028-185049.jpg" alt="JBoss Tools Icon" width="128" height="128" /><br />
Use Eclipse with the JBoss Tools plugin instead of  <a title="JBoss Developer Studio - Downloads" href="http://devstudio.jboss.com/download/" target="_blank">JBoss Developer Studio</a>? It can get somewhat tricky to get the right version of the tools plugin to work with the compatible version of Eclipse and the correct version of JSF components, etc.</p>
<p>JBoss Dev Studio is a branded version of a Eclipse packed with the right version of JBoss Tools. The dev studio is usually bundled with a developer subscription from RedHat for $99. (I&#8217;ve been told, however, by <a title="Max's Blog » What was I thinking ?" href="http://blog.xam.dk/" target="_blank">Max Rydahl Andersen</a> a JBoss employee who is also one of the developers of JBoss tools and the developer studio that the JBoss Developer Studio IDE itself is actually free without the JBoss commercial runtimes &#8211; i.e. JBoss EAP).</p>
<p>If you stick with Eclipse IDE with the JBoss tools plugin, I came up with the following matrix of the set of tools showing the coupling of compatible versions.<span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p><h2 class="wp-table-reloaded-table-name-id-1 wp-table-reloaded-table-name">JBoss Tools Compatibility Matrix</h2>

<table id="wp-table-reloaded-id-1-no-1" class="wp-table-reloaded wp-table-reloaded-id-1">
<thead>
	<tr class="row-1 odd">
		<th class="column-1">Eclipse</th><th class="column-2">JBoss Tools</th><th class="column-3">JBDS</th><th class="column-4">JBoss EAP</th><th class="column-5">JBoss AS (Community)</th><th class="column-6">Seam</th><th class="column-7">JSF</th><th class="column-8">RichFaces</th>
	</tr>
</thead>
<tbody class="row-hover">
	<tr class="row-2 even">
		<td class="column-1">3.6 / Helios</td><td class="column-2">3.2</td><td class="column-3">3.0.0</td><td class="column-4">4.3,5.0,5.1</td><td class="column-5">5.1, 5.0, 4.2, 4.0, 3.2</td><td class="column-6">2.2, 2.1, 2.0, 1.2</td><td class="column-7">2.0 (in VPE), 1.2, 1.1</td><td class="column-8">3.3.x</td>
	</tr>
	<tr class="row-3 odd">
		<td class="column-1">3.5/Galileo</td><td class="column-2">3.1.0</td><td class="column-3">3.0.0</td><td class="column-4">4.3, 5.0</td><td class="column-5">5.1, 5.0, 4.2, 4.0, 3.2</td><td class="column-6">2.2, 2.1, 2.0, 1.2</td><td class="column-7">2.0 (in VPE), 1.2, 1.1</td><td class="column-8">3.3.x</td>
	</tr>
	<tr class="row-4 even">
		<td class="column-1">3.4.2/Ganymede</td><td class="column-2">3.0.x</td><td class="column-3">2.1.0</td><td class="column-4">4.3, 5.0</td><td class="column-5">5.0, 4.2, 4.0, 3.2</td><td class="column-6">2.2, 2.1, 2.0, 1.2</td><td class="column-7">1.2, 1.1</td><td class="column-8">3.3.1</td>
	</tr>
	<tr class="row-5 odd">
		<td class="column-1">3.3.2/Europa</td><td class="column-2">2.1.2</td><td class="column-3">1.1.0</td><td class="column-4">4.3</td><td class="column-5">5.0, 4.2, 4.0, 3.2</td><td class="column-6">2.0, 1.2</td><td class="column-7">1.2, 1.1</td><td class="column-8">3.3.0</td>
	</tr>
	<tr class="row-6 even">
		<td class="column-1">3.3.1.1/Europa</td><td class="column-2">2.0.1</td><td class="column-3">1.0.0</td><td class="column-4">4.2</td><td class="column-5">4.2, 4.0, 3.2</td><td class="column-6">2.0, 1.2</td><td class="column-7">1.2, 1.1</td><td class="column-8">3.1.0</td>
	</tr>
</tbody>
</table>
<span id="more-18"></span><img class="alignnone size-full" src="http://gokhan.ozar.net/wp-content/uploads/20111028-185142.jpg" alt="20111028-185142.jpg" /><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/matrix-of-supported-platforms-for-jboss-tools/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Hibernate Derived Properties &#8211; @Formula Annotation</title>
		<link>http://gokhan.ozar.net/hibernate-derived-properties-formula-annotation/</link>
		<comments>http://gokhan.ozar.net/hibernate-derived-properties-formula-annotation/#comments</comments>
		<pubDate>Tue, 25 Oct 2011 12:57:12 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Java EE]]></category>
		<category><![CDATA[ORM]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=15</guid>
		<description><![CDATA[In Hibernate a derived property (also called a calculated property) is a read-only property whose value is calculated at fetch time using SQL expressions. Example: For an employee entity with properties such as an id and the employee name also &#8230; <a href="http://gokhan.ozar.net/hibernate-derived-properties-formula-annotation/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-25" title="Hibernate logo" src="http://gokhan.ozar.net/wp-content/uploads/Hibernate_logo_s.gif" alt="Hibernate" width="160" height="38" />In Hibernate a derived property (also called a calculated property) is a read-only property whose value is calculated at fetch time using SQL expressions.</p>
<p>Example: For an employee entity with properties such as an id and the employee name also a monthlySalary property, you might also want to have a yearlySalary which is not necessarily stored in the database.</p>
<pre class="brush: java; gutter: false">package net.ozar.exp.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name="EMPLOYEE")
public class Employee implements java.io.Serializable {

	private static final long serialVersionUID = -7311873726885796936L;

	@Id
	@Column(name="ID")
	private Integer id;

	@Column(name="FIRST_NAME", length=31)
	private String firstName;

	@Column(name="LAST_NAME", length=31)
	private String lastName;

	@Column(name="MONTHLY_SALARY")
	private float monthlySalary;

	public Employee() {
	}

	// getters and setters
     // ...

	public float getMonthlySalary() {
		return monthlySalary;
	}

	public void setMonthlySalary(float monthlySalary) {
		this.monthlySalary = monthlySalary;
	}

     /* This artificial property - as I call it - is a kind of a calculated property, but not with Hibernate derived property support - not just yet */
	public float getYearlySalary() {
		return this.monthlySalary * 12;
	}

}</pre>
<p>The above example gives us a simple calculation in memory for just screen output without Hibernate&#8217;s derived property or the <em>@Formula</em> support.  Now take a moment to reflect that we need all the employees whose yearly salary average is above $5000. Then what? In this case, you might wanna make use of Hibernate&#8217;s derived property feature.<br />
<span id="more-15"></span><br />
<span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<p>To define a derived property in Hibernate, we use the <em>@Formula</em> annotation or the &lt;formula&gt; tag in the hbm.xml definition file.</p>
<pre class="brush: java; gutter: true">package net.ozar.exp.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;

import org.hibernate.annotations.Formula;

@Entity
@Table(name="EMPLOYEE")
public class Employee implements java.io.Serializable {

	private static final long serialVersionUID = -7311873726885796936L;

	@Id
	@Column(name="ID")
	private Integer id;

	@Column(name="FIRST_NAME", length=31)
	private String firstName;

	@Column(name="LAST_NAME", length=31)
	private String lastName;

	@Column(name="MONTHLY_SALARY")
	private float monthlySalary;

	@Formula("MONTHLY_SALARY*12")
        private float yearlySalary;

	public Employee() {
	}

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public float getMonthlySalary() {
		return monthlySalary;
	}

	public void setMonthlySalary(float monthlySalary) {
		this.monthlySalary = monthlySalary;
	}

	public float getYearlySalary() {
		return yearlySalary;
	}

}</pre>
<p>Please note that in the above example the value of the @Formula annotation is actually an SQL expression which refers to the &#8220;MONTHLY_SALARY&#8221; column in the database and not the Hibernate property <em>monthlySalary</em>.</p>
<blockquote><p>Please note that the @Formula annotation is specific to Hibernate and is not present in other JPA implementations &#8211; at least not just yet.</p></blockquote>
<p>A more complex example:</p>
<pre class="brush: java; gutter: true">@Formula("(select min(l.creation_date) from Logs l where l.customer_id = id)")
private Date firstLoginDate;</pre>
<p>In this example the query is a native SQL query and id (as the parameter) is the id of the current entity.</p>
<pre class="brush: java; gutter: false">@OneToMany(mappedBy="user",cascade=CascadeType.ALL, fetch=FetchType.LAZY)
@BatchSize(size=100)
private Set&lt;Log&gt; logs = new HashSet&lt;Log&gt;();

@Formula("(select min(l.creation_date) from logs l where l.user_id = id)")
private Date firstLoginDate;

@Formula("(select max(l.creation_date) from logs l where l.user_id = id)")
private Date lastLoginDate;

@Formula("(select coalesce(extract ('day' from age(max(l.creation_date))), 9999) from logs l where l.user_id = id)")
private int daysSinceLastLogin;

// ...

public Date getFirstLoginDate() {
  return firstLoginDate;
}

public Date getLastLoginDate() {
  return lastLoginDate;
}

public int getDaysSinceLastLogin() {
   return daysSinceLastLagin;
}</pre>
<p>And the log entity would be something like:</p>
<pre class="brush: java; gutter: false">@Entity
@Table(name = "LOGS")
public class Log {
 //  ...
  @NotNull
  @Column(name="CREATION_DATE")
  private Date creationDate;

  @ManyToOne
  @JoinColumn(name="USER_ID")
  private User user;

  @PrePersist
  public void prePersist()  {
    creationDate = new Date();
  }
}</pre>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/hibernate-derived-properties-formula-annotation/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Oracle Database 10g XE Installation and Configuration</title>
		<link>http://gokhan.ozar.net/oracle10g-xe/</link>
		<comments>http://gokhan.ozar.net/oracle10g-xe/#comments</comments>
		<pubDate>Sun, 25 Sep 2011 12:21:16 +0000</pubDate>
		<dc:creator>Gökhan Ozar</dc:creator>
				<category><![CDATA[Database]]></category>
		<category><![CDATA[Oracle]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Tech Tips]]></category>

		<guid isPermaLink="false">http://gokhan.ozar.net/?p=1</guid>
		<description><![CDATA[In this article I will write about installing the Oracle Database 10g XE on Windows and changing the default port number for HTTP and optionally for FTP. The installer does not provide any customization option and you end up with &#8230; <a href="http://gokhan.ozar.net/oracle10g-xe/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-10852" style="margin: 10px;" title="Oracle" src="http://devblog.ozar.net/wp-content/res/oracle_logo_small1.gif" alt="Oracle logo" width="133" height="18" />In this article I will write about installing the Oracle Database 10g XE on Windows and changing the default port number for HTTP and optionally for FTP. The installer does not provide any customization option and you end up with the DB server instantly up and running reserving the port 1521 (a default for Oracle database servers), including an embedded HTTP listener set to a default port of 8080 which might conflict with some existing Java application servers or servlet containers such as Tomcat, JBoss Application Server and Glassfish which use the same port by default. Although it&#8217;s easy to start and stop the Oracle database with the shortcuts pre-installed in the Start menu, its http listener remains &#8220;on&#8221; at all times with no shortcut to be turned on and off easily.</p>
<p>In my case I already have Tomcat and Glassfish which are set to use the 8080 port as well, so I will show you how to modify the port number of Oracle 10g XE as I go along.</p>
<h3>About APEX or what I would normally call Oracle 10g XE</h3>
<p>Oracle Database 10g Express Edition (Oracle Database XE also goes by an abbreviated code name APEX) is an entry-level, small-footprint database based on the Oracle Database 10g Release 2 code base that&#8217;s free to develop, deploy, and distribute; fast to download; and simple to administer. Oracle Database XE is a great starter database for:</p>
<ul>
<li>Developers working on PHP, Java, .NET, XML, and Open Source applications</li>
<li>DBAs who need a free, starter database for training and deployment</li>
<li>Independent Software Vendors (ISVs) and hardware vendors who want a starter database to distribute free of charge</li>
<li>Educational institutions and students who need a free database for their curriculum.</li>
</ul>
<p>With Oracle Database XE, you can now develop and deploy applications with a powerful, proven, industry-leading infrastructure, and then upgrade when necessary without costly and complex migrations.</p>
<p><span id="more-1"></span></p>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 728x90, created 11/2/11 */
google_ad_slot = "1638105903";
google_ad_width = 728;
google_ad_height = 90;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
<h3>Installing Oracle Database 10g Express Edition</h3>
<p>Just download the double-clickable installer (named OracleXEUniv.exe ) from Oracle&#8217;s web site whose URL at the time of this writing was: http://www.oracle.com/technetwork/database/express-edition/downloads/index.html</p>
<p>Alternatively from the following (fast &amp; direct download) link:</p>
<p><a class="downloadlink" href="http://gokhan.ozar.net/wp-content/plugins/download-monitor/download.php?id=1" title="Version10g XE downloaded 17 times" >Oracle Database 10g Express Edition for Microsoft Windows (17)</a> for Windows</p>
<p>Double-click OracleXEUniv.exe and you should see a typical InstallShield window:</p>
<p><img class="alignnone size-full wp-image-10849" title="oracle_xe_installation" src="http://devblog.ozar.net/wp-content/res/oracle_xe_installation.gif" alt="Oracle Database Express Edition (XE) Installation" width="504" height="379" /></p>
<p><img class="alignright size-full wp-image-10850" title="oracle_xe_start_menu" src="http://devblog.ozar.net/wp-content/res/oracle_xe_start_menu.gif" alt="Start > All Programs > Oracle Database 10g Express Edition > Go to the database Home Page&#8221; width=&#8221;408&#8243; height=&#8221;313&#8243; /></p>
<p>At some point in the installation you will be asked to provide a password as the database SYSTEM DBA. Note this down. After the installation is completed, you can connect to the web-based database control panel by selecting the shortcuts from the Start menu:</p>
<p><em>Start &gt; All Programs &gt; Oracle Database 10g Express Edition &gt; Go to the database Home Page</em></p>
<p>Your default browser should pop-up a new window asking you some login credentials for arriving at the database home page.</p>
<p>Username: SYSTEM</p>
<p>Password is what you set at the time of the installation.</p>
<p><a href="http://devblog.ozar.net/wp-content/res/apex_home_page.gif"><img class="alignnone size-full wp-image-10851" title="apex_home_page" src="http://devblog.ozar.net/wp-content/res/apex_home_page.gif" alt="APEX home page" width="640" height="493" /></a></p>
<h3>Changing the default port number of APEX (the port # 8080 of the http listener)</h3>
<p>Now I don&#8217;t want APEX to block my Java EE application servers who need (and probably deserve) the 8080 port more. I&#8217;m quite OK with the light database server itself which is listening the port 1521.</p>
<p><a href="http://devblog.ozar.net/wp-content/res/oracle_xe_run_sql_commandline.gif"><img class="alignright size-medium wp-image-10856" title="oracle_xe_run_sql_commandline" src="http://devblog.ozar.net/wp-content/res/oracle_xe_run_sql_commandline-300x276.gif" alt="Run SQL Command line" width="300" height="276" /></a>Go to S<em>tart &gt; All Programs &gt; Oracle Database 10g Express Edition &gt; Run SQL Command Line</em></p>
<p>In the console window type the commands as shown below and in the screenshot:</p>
<p><code>SQL&gt; -- get current status<br />
SQL&gt; select dbms_xdb.gethttpport as "HTTP-Port"<br />
, dbms_xdb.getftpport as "FTP-Port" from dual;</code></p>
<p>&nbsp;</p>
<p><code>HTTP-Port FTP-Port<br />
---------- ----------<br />
8080 0</code></p>
<p>You can change the http port and the ftp port to whatever you like (keep in mind that you need special privileges for ports &lt; 1024 on Unix/Linux systems).</p>
<p><code>SQL&gt; -- set http port and ftp port<br />
SQL&gt; begin<br />
2 dbms_xdb.sethttpport('8888');<br />
3 dbms_xdb.setftpport('2100');<br />
4 end;<br />
5 /</code></p>
<p><code>PL/SQL procedure successfully completed.</code></p>
<p>SQL&gt; select dbms_xdb.gethttpport as &#8220;HTTP-Port&#8221;<br />
, dbms_xdb.getftpport as &#8220;FTP-Port&#8221; from dual;</p>
<p>&nbsp;</p>
<p><code>HTTP-Port FTP-Port<br />
---------- ----------<br />
8888 2100</code></p>
<p><img class="size-full wp-image-10853 alignnone" title="apex_changing_port2" src="http://devblog.ozar.net/wp-content/res/apex_changing_port2.gif" alt="Oracle SQL Command Line" width="668" height="331" /></p>
<p>In my case I&#8217;m changing the HTTP port to 8888.</p>
<p>There I&#8217;m also changing the FTP port to 2100 which was 0 (disabled) by default.</p>
<p>If you only want to use the database without allowing access via HTTP or FTP then you can disable both:</p>
<pre>SQL&gt; -- disable http and ftp access
SQL&gt; begin
 2    dbms_xdb.sethttpport('0');
 3    dbms_xdb.setftpport('0');
 4  end;
 5  /

PL/SQL procedure successfully completed.

SQL&gt; -- get current status
SQL&gt; select dbms_xdb.gethttpport as "HTTP-Port"
            , dbms_xdb.getftpport as "FTP-Port" from dual;

HTTP-Port   FTP-Port
---------- ----------
        0          0</pre>
<p><span style="color: #ff0000;"> <script type="text/javascript"><!--
google_ad_client = "pub-2035820168336712";
/* gokhan.ozar.net 336x280, created 11/2/11 */
google_ad_slot = "4419315506";
google_ad_width = 336;
google_ad_height = 280;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></span></p>
]]></content:encoded>
			<wfw:commentRss>http://gokhan.ozar.net/oracle10g-xe/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

