<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Knowledge Cluster</title>
	<atom:link href="http://josebobsantos.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://josebobsantos.wordpress.com</link>
	<description>A programming blog of Bob Santos</description>
	<lastBuildDate>Sun, 11 Sep 2011 22:22:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='josebobsantos.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Knowledge Cluster</title>
		<link>http://josebobsantos.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://josebobsantos.wordpress.com/osd.xml" title="Knowledge Cluster" />
	<atom:link rel='hub' href='http://josebobsantos.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Basic JSF 2.0 Maven Configuration (with Eclipse and Tomcat 7.0)</title>
		<link>http://josebobsantos.wordpress.com/2011/09/12/basic-jsf-2-0-maven-configuration-with-eclipse-and-tomcat-7-0/</link>
		<comments>http://josebobsantos.wordpress.com/2011/09/12/basic-jsf-2-0-maven-configuration-with-eclipse-and-tomcat-7-0/#comments</comments>
		<pubDate>Sun, 11 Sep 2011 21:41:40 +0000</pubDate>
		<dc:creator>josebobsantos</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Java Server Faces]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[jsf 2]]></category>
		<category><![CDATA[maven]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[tomcat]]></category>

		<guid isPermaLink="false">http://josebobsantos.wordpress.com/?p=153</guid>
		<description><![CDATA[I&#8217;ve decided to learn JSF 2 to upgrade my knowledge of JSF. I would have searched for a JSF 2 Maven archetype but I wanted to learn how to configure it myself so here&#8217;s a basic hello world application (I&#8217;m assuming that you have a basic knowledge of Maven, if not please go here). pom.xml [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=153&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>
I&#8217;ve decided to learn JSF 2 to upgrade my knowledge of JSF. I would have searched for a JSF 2 Maven archetype but I wanted to learn how to configure it myself so here&#8217;s a basic hello world application (I&#8217;m assuming that you have a basic knowledge of Maven, if not please go <a href="http://maven.apache.org" title="here" target="_blank">here</a>).
</p>
<p><span id="more-153"></span></p>
<h3>pom.xml</h3>
<p>
Let&#8217;s start with the </code>pom.xml</code>...</p>
<pre class="brush: xml;">
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;
    &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

    &lt;groupId&gt;com.sample&lt;/groupId&gt;
    &lt;artifactId&gt;jsf&lt;/artifactId&gt;
    &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
    &lt;packaging&gt;war&lt;/packaging&gt;
    &lt;name&gt;jsf-sample&lt;/name&gt;

	&lt;repositories&gt;
		&lt;repository&gt;
			&lt;id&gt;jboss&lt;/id&gt;
			&lt;name&gt;JBoss Repository for Maven&lt;/name&gt;
			&lt;url&gt;https://repository.jboss.org/nexus/content/groups/public/&lt;/url&gt;
		&lt;/repository&gt;
		&lt;repository&gt;
			&lt;id&gt;central&lt;/id&gt;
			&lt;name&gt;Maven Repository Switchboard&lt;/name&gt;
			&lt;url&gt;http://repo1.maven.org/maven2&lt;/url&gt;
		&lt;/repository&gt;
		&lt;repository&gt;
			&lt;id&gt;maven2-repository.java.net&lt;/id&gt;
			&lt;name&gt;Java.net Repository for Maven&lt;/name&gt;
			&lt;url&gt;http://download.java.net/maven/2/&lt;/url&gt;
		&lt;/repository&gt;
	&lt;/repositories&gt;

    &lt;dependencies&gt;
    	&lt;dependency&gt;
			&lt;groupId&gt;javax&lt;/groupId&gt;
			&lt;artifactId&gt;javaee-web-api&lt;/artifactId&gt;
			&lt;version&gt;6.0&lt;/version&gt;
			&lt;scope&gt;provided&lt;/scope&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
			&lt;artifactId&gt;jsf-api&lt;/artifactId&gt;
			&lt;version&gt;${jsf.version}&lt;/version&gt;
		&lt;/dependency&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;com.sun.faces&lt;/groupId&gt;
			&lt;artifactId&gt;jsf-impl&lt;/artifactId&gt;
			&lt;version&gt;${jsf.version}&lt;/version&gt;
		&lt;/dependency&gt;
    &lt;/dependencies&gt;

    &lt;build&gt;
        &lt;plugins&gt;
            &lt;plugin&gt;
                &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                &lt;version&gt;2.3.2&lt;/version&gt;
                &lt;configuration&gt;
                    &lt;source&gt;1.6&lt;/source&gt;
                    &lt;target&gt;1.6&lt;/target&gt;
                &lt;/configuration&gt;
            &lt;/plugin&gt;
            &lt;plugin&gt;
              	&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
             	&lt;artifactId&gt;maven-war-plugin&lt;/artifactId&gt;
              	&lt;version&gt;2.1.1&lt;/version&gt;
              	&lt;configuration&gt;
                  	&lt;failOnMissingWebXml&gt;false&lt;/failOnMissingWebXml&gt;
                  	&lt;contextRoot&gt;/jsf&lt;/contextRoot&gt;
              	&lt;/configuration&gt;
          	&lt;/plugin&gt;
            &lt;plugin&gt;
          	 	&lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
              	&lt;artifactId&gt;maven-eclipse-plugin&lt;/artifactId&gt;
              	&lt;version&gt;2.8&lt;/version&gt;
              	&lt;configuration&gt;
                  	&lt;wtpmanifest&gt;true&lt;/wtpmanifest&gt;
		          	&lt;wtpversion&gt;2.0&lt;/wtpversion&gt;
		          	&lt;manifest&gt;${basedir}/src/main/resources/META-INF/MANIFEST.MF&lt;/manifest&gt;
              	&lt;/configuration&gt;
	        &lt;/plugin&gt;
        &lt;/plugins&gt;
    &lt;/build&gt;

    &lt;properties&gt;
        &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
        &lt;jsf.version&gt;2.1.2&lt;/jsf.version&gt;
    &lt;/properties&gt;
&lt;/project&gt;
</pre>
<p>If you're using a web server such as Tomcat 6.0 or above you will need to have jsf-api and jsf-impl. I've decided to use the jars in the public JBoss repository because the ones in the central Maven repo will produce an error during server start-up: <br /><code>java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/faces/FacesException</code><br />
<br />
You can use any Java EE 6 server instead but that is not part of this post because there maybe additional configurations such as ear pom configuration which I haven't tried yet.</p>
<h3>web.xml</h3>
<p>
Next, we need to configure the <code>web.xml</code> file to direct <code>*.xhtml</code> requests to the FacesServlet.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
  xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
  xmlns:web=&quot;http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
  xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd&quot;
  version=&quot;2.5&quot;&gt;
  &lt;!-- Minimum requirement for JSF 2 is a servlet 2.5 declaration --&gt;
  &lt;!-- Map FacesServlet --&gt;
  &lt;servlet&gt;
    &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
    &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
  &lt;/servlet&gt;
  &lt;servlet-mapping&gt;
    &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
    &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
  &lt;/servlet-mapping&gt;
  &lt;!-- For better error messages during development --&gt;
  &lt;context-param&gt;
    &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
    &lt;param-value&gt;Development&lt;/param-value&gt;
  &lt;/context-param&gt;

  &lt;welcome-file-list&gt;
    &lt;welcome-file&gt;index.jsp&lt;/welcome-file&gt;
    &lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
    &lt;welcome-file&gt;index.xhtml&lt;/welcome-file&gt;
  &lt;/welcome-file-list&gt;
&lt;/web-app&gt;
</pre>
<p>Mapping <code>*.xhtml</code> to <code>FacesServlet</code> will allow us to use JSF tags in our xhtml files.
</p>
<h3>faces-config.xml</h3>
<p>At the minimum we need to have an empty <code>faces-config.xml</code> in WEB-INF.</p>
<pre class="brush: xml;">
&lt;?xml version=&quot;1.0&quot;?&gt;
&lt;faces-config xmlns=&quot;http://java.sun.com/xml/ns/javaee&quot;
   xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
   xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd&quot;
   version=&quot;2.0&quot;&gt;
  &lt;!-- Empty but needed --&gt;
&lt;/faces-config&gt;
</pre>
<h3>Test</h3>
<p>
To test the configuration I created a basic <code>index.xhtml</code> file which uses some JSF tags (with the h prefix) in src/main/webapp.</p>
<pre class="brush: xml;">
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;

&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;
	  xmlns:h=&quot;http://java.sun.com/jsf/html&quot;&gt;
&lt;h:head&gt;
	&lt;title&gt;JSF | Index&lt;/title&gt;
&lt;/h:head&gt;
&lt;h:body&gt;
	&lt;h1&gt;Hello World!&lt;/h1&gt;
&lt;/h:body&gt;
&lt;/html&gt;
</pre>
<p>Just run the <code>mvn clean eclipse:clean eclipse:eclipse install</code>, import in Eclipse, create a server, add the project, run the server and go to <code>index.xhtml</code>.
</p>
<p>I hope this helped you. Cheers!</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/josebobsantos.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/josebobsantos.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/josebobsantos.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/josebobsantos.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/josebobsantos.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/josebobsantos.wordpress.com/153/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/josebobsantos.wordpress.com/153/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/josebobsantos.wordpress.com/153/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=153&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://josebobsantos.wordpress.com/2011/09/12/basic-jsf-2-0-maven-configuration-with-eclipse-and-tomcat-7-0/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37e46fd75e6e1bf1377c48499495f45d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">josebobsantos</media:title>
		</media:content>
	</item>
		<item>
		<title>Use the New JDBC Driver for MS SQL Server</title>
		<link>http://josebobsantos.wordpress.com/2009/08/16/use-the-new-jdbc-driver-for-ms-sql-server/</link>
		<comments>http://josebobsantos.wordpress.com/2009/08/16/use-the-new-jdbc-driver-for-ms-sql-server/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 19:12:31 +0000</pubDate>
		<dc:creator>josebobsantos</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[JDBC]]></category>
		<category><![CDATA[MS SQL Server]]></category>
		<category><![CDATA[Object Relational Mapping]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://josebobsantos.wordpress.com/?p=138</guid>
		<description><![CDATA[I&#8217;ve used MySQL with my example on my Hibernate posts but since we are using MS SQL Server 2000 in my class(I know, we should be upgrading to at least SQL Server 2005&#8230;) I thought I&#8217;d create an example using SQL Server. So there I was reconstructing everything that I mentioned starting with Java Persistence [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=138&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve used MySQL with my example on my Hibernate posts but since we are using MS SQL Server 2000 in my class(I know, we should be upgrading to at least SQL Server 2005&#8230;) I thought I&#8217;d create an example using SQL Server.</p>
<p>So there I was reconstructing everything that I mentioned starting with <a href="http://josebobsantos.wordpress.com/2009/08/15/java-persistence-with-hibernate-part-4-create-the-mapping-file-and-configuration-file/">Java Persistence with Hibernate Part 2 &#8211; Getting Started</a> until I was done with my test class to see if everything works and that&#8217;s what I was expecting but I was wrong. Instead I got this error:
<pre class="brush: java;">Exception in thread &quot;main&quot; java.lang.AbstractMethodError: com.microsoft.jdbc.base.BaseDatabaseMetaData.supportsGetGeneratedKeys()Z</pre>
<p><span id="more-138"></span><br />
I immediately blamed the JDBC driver I have for SQL Server 2000 and then I also remembered that there&#8217;s a <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=99b21b65-e98f-4a61-b811-19912601fdc9&amp;displaylang=en">new JDBC version already for SQL Server</a>. Sure enough when I changed to sqljdbc4.jar(I&#8217;m using JDK 6.0, use sqljdbc.jar for JDK 5.0) and changed the driver class to com.microsoft.sqlserver.jdbc.SQLServerDriver everything went smoothly and the application executed correctly.</p>
<p>Hope this helps someone cause it&#8217;s really hard to find the solution for the error that I encountered if you&#8217;re not familiar with the history of JDBC with SQL Server. For more information on using the new driver please visit <a href="http://msdn.microsoft.com/en-us/library/ms378526.aspx">Using the JDBC Driver</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/josebobsantos.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/josebobsantos.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/josebobsantos.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/josebobsantos.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/josebobsantos.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/josebobsantos.wordpress.com/138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/josebobsantos.wordpress.com/138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/josebobsantos.wordpress.com/138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=138&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://josebobsantos.wordpress.com/2009/08/16/use-the-new-jdbc-driver-for-ms-sql-server/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37e46fd75e6e1bf1377c48499495f45d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">josebobsantos</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Persistence with Hibernate Part 4 &#8211; Create the Mapping File and Configuration File</title>
		<link>http://josebobsantos.wordpress.com/2009/08/15/java-persistence-with-hibernate-part-4-create-the-mapping-file-and-configuration-file/</link>
		<comments>http://josebobsantos.wordpress.com/2009/08/15/java-persistence-with-hibernate-part-4-create-the-mapping-file-and-configuration-file/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 10:26:46 +0000</pubDate>
		<dc:creator>josebobsantos</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Object Relational Mapping]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://josebobsantos.wordpress.com/?p=128</guid>
		<description><![CDATA[We need to tell Hibernate how our persistent class(Student.java) maps to our table(student_table) for Hibernate to be able to load and persist(save) data. Create the Mapping File The basic structure of a mapping file is like this: The DOCTYPE is required in the mapping file. You can use it for auto-completion of the XML elements [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=128&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>We need to tell Hibernate how our persistent class(Student.java) maps to our table(student_table) for Hibernate to be able to load and persist(save) data.</p>
<p><strong>Create the Mapping File</strong></p>
<p>The basic structure of a mapping file is like this:</p>
<pre class="brush: xml;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE hibernate-mapping PUBLIC
        &quot;-//Hibernate/Hibernate Mapping DTD 3.0//EN&quot;
        &quot;http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd&quot;&gt;

&lt;hibernate-mapping package=&quot;com.phoenixone.hibernate.model&quot;&gt;
	&lt;class name=&quot;com.tutorial.enrollment.model.Student&quot; table=&quot;student&quot;&gt;
		&lt;id name=&quot;id&quot; column=&quot;student_id&quot;&gt;
			&lt;generator class=&quot;org.hibernate.id.enhanced.SequenceStyleGenerator&quot; /&gt;
		&lt;/id&gt;
		&lt;property name=&quot;firstName&quot; column=&quot;first_name&quot; /&gt;
		&lt;property name=&quot;lastName&quot; column=&quot;last_name&quot; /&gt;
	&lt;/class&gt;
&lt;/hibernate-mapping&gt;
</pre>
<p><span id="more-128"></span><br />
The <strong>DOCTYPE</strong> is required in the mapping file. You can use it for auto-completion of the XML elements of the mapping file. The DTD is included in hibernate3.jar.</p>
<p><strong>&lt;hibernate-mapping&gt;</strong> is the root element of the XML mapping file. You need to provide the package where the class belongs.</p>
<p><strong>&lt;class&gt;</strong> tags is used for mapping the persistent class and other classes to which your persistent class is dependent.<br />
<em>e.g. If we have an Address property</em>
<pre class="brush: java;">private Address address;</pre>
<p><em> inside the Student class then we need to create another &lt;class&gt; tag for Address but that&#8217;s another topic.</em> </p>
<p>The <strong>&lt;id&gt;</strong> tag is used to mapped the primary key in the table to the property in the class.  </p>
<p>The <strong>&lt;generator&gt;</strong> tag provides auto-generation of the id. You can choose from a list of generator classes or short names which you can find <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html_single/#mapping-declaration-id">here</a>. You can also plugin your own <a href="http://blog.dagitab.com/index.php?blog=1&amp;p=30&amp;disp=single&amp;more=1&amp;c=1&amp;tb=1&amp;pb=1">generator strategy</a>.</p>
<p>The <strong>&lt;property&gt;</strong> tag is used to map the other properties of the class. Just make sure that the value of name attribute has the same casing as you used in the class file.</p>
<p>After creating the mapping file save it as <strong>Student.hbm.xml</strong> and put it on the same directory as Student.java. All mapping files should have the same name as the class it maps and ends with <strong>.hbm.xml</strong>.</p>
<p><strong>Create the Hibernate Configuration File</strong></p>
<p>Ok, at this point we already have our database(enrollment) and persistent class(Student.java) which was done in <a href="http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-3-%E2%80%93-create-the-database-and-persistent-class/">Part 3</a> and earlier in this post we have the mapping file for Student.java<a href="#mapping-file">(Student.hbm.xml)</a>. There&#8217;s only one thing left to configure so we can store and load objects with Hibernate and that is tell Hibernate our database configuration, how to locate the mapping files(*.hbm.xml), etc.</p>
<p>Here&#8217;s how our configuration file may look like&#8230;</p>
<pre class="brush: xml;">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE hibernate-configuration PUBLIC
        &quot;-//Hibernate/Hibernate Configuration DTD 3.0//EN&quot;
        &quot;http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd&quot;&gt;

&lt;hibernate-configuration&gt;
	&lt;session-factory&gt;
		&lt;property name=&quot;connection.driver_class&quot;&gt;com.mysql.jdbc.Driver&lt;/property&gt;
		&lt;property name=&quot;connection.url&quot;&gt;jdbc:mysql://localhost/enrollment&lt;/property&gt;
		&lt;property name=&quot;connection.username&quot;&gt;root&lt;/property&gt;
		&lt;property name=&quot;connection.password&quot;&gt;root&lt;/property&gt;

		&lt;property name=&quot;dialect&quot;&gt;org.hibernate.dialect.MySQL5InnoDBDialect&lt;/property&gt;
		&lt;property name=&quot;show_sql&quot;&gt;true&lt;/property&gt;
		&lt;property name=&quot;hbm2ddl.auto&quot;&gt;update&lt;/property&gt;
		&lt;property name=&quot;current_session_context_class&quot;&gt;thread&lt;/property&gt;

		&lt;mapping resource=&quot;com/tutorial/enrollment/model/Student.hbm.xml&quot; /&gt;
	&lt;/session-factory&gt;
&lt;/hibernate-configuration&gt;
</pre>
<p>The DOCTYPE here is different from the mapping file&#8217;s DOCTYPE.</p>
<p><strong>&lt;hibernate-configuration&gt;</strong> is the root element of the file.</p>
<p><strong>&lt;session-factory&gt;</strong> allows you to configure Hibernate&#8217;s SessionFactory which is the one responsible for a specific database. The SessionFactory is also the one responsible for creating Session objects that will allow us to store and load objects as we will see in Part 5. If you have several databases then you should have several <strong>&lt;session-factory&gt;</strong> elements too.</p>
<p>The first four properties take care of our database connection. You can search for your particular database&#8217;s connection configuration by searching on how to use the JDBC driver for it. As for MySQL it&#8217;s <a href="http://dev.mysql.com/doc/refman/5.0/en/connector-j-usagenotes-basic.html#connector-j-examples-connection-drivermanager">here</a>.</p>
<p>The <strong>dialect</strong> property determines what particular SQL variant Hibernate will generate depending on your database. For other dialects go <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/session-configuration.html#configuration-optional-dialects">here</a>.</p>
<p>The <strong>show_sql</strong> property tells Hibernate to print the generated sql to the console.</p>
<p>If by chance you accidentally dropped the database for our persistent class you can add <strong>hbm2ddl.auto</strong> and it will automatically create the database schema for you, handy isn&#8217;t it?</p>
<p>The <strong>current_session_context_class</strong> property enables the automatic session context management.</p>
<p>You can visit <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/session-configuration.html#configuration-optional">this page</a> if you want to learn about other configurations you can set.</p>
<p><a href="http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-3-%E2%80%93-create-the-database-and-persistent-class/">Part 3 – Create the Database and Persistent Class</a> o0o Part 5 &#8211; Creating a SessionFactory Helper and Storing/Loading Objects</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/josebobsantos.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/josebobsantos.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/josebobsantos.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/josebobsantos.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/josebobsantos.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/josebobsantos.wordpress.com/128/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/josebobsantos.wordpress.com/128/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/josebobsantos.wordpress.com/128/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=128&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://josebobsantos.wordpress.com/2009/08/15/java-persistence-with-hibernate-part-4-create-the-mapping-file-and-configuration-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37e46fd75e6e1bf1377c48499495f45d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">josebobsantos</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Persistence with Hibernate Part 3 – Create the Database and Persistent Class</title>
		<link>http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-3-%e2%80%93-create-the-database-and-persistent-class/</link>
		<comments>http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-3-%e2%80%93-create-the-database-and-persistent-class/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 17:44:44 +0000</pubDate>
		<dc:creator>josebobsantos</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Object Relational Mapping]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://josebobsantos.wordpress.com/?p=107</guid>
		<description><![CDATA[Create a Database In using Hibernate you may either create the database first and create the class we need to persist or vice-versa. With the SQL code above, we&#8217;ve created a database named &#8220;enrollment&#8221; and a table named &#8220;student&#8221; with three columns(student_id, first_name and last_name) with student_id as our primary key(unique identifier). Create the Eclipse [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=107&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Create a Database</strong></p>
<p>In using Hibernate you may either create the database first and create the class we need to persist or vice-versa.</p>
<pre class="brush: sql;">
create database enrollment;
create table student(
 student_id int,
 first_name varchar(40),
 last_name varchar(40),
 primary key(student_id)
);
</pre>
<p>With the SQL code above, we&#8217;ve created a database named &#8220;enrollment&#8221; and a table named &#8220;student&#8221; with three columns(student_id, first_name and last_name) with student_id as our primary key(unique identifier).<br />
<span id="more-107"></span><br />
<strong>Create the Eclipse Project</strong></p>
<p>Again, you don&#8217;t need to have an eclipse project just adjust what is done here to your development environment.</p>
<ol>
<li>
 Create a new Java project in this case I named the project &#8220;com.tutorial.enrollment&#8221;. <a href="http://i936.photobucket.com/albums/ad208/josebobsantos/hibernate3.gif">Image</a>
 </li>
<li>
 Add the libraries mentioned in <a href="http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-2-getting-started#libraries">Part 2</a> to the build path <a href="http://i936.photobucket.com/albums/ad208/josebobsantos/hibernate4.gif">Image 1</a>, <a href="http://i936.photobucket.com/albums/ad208/josebobsantos/hibernate5.gif">Image 2</a>
 </li>
</ol>
<p><strong>Create the Student Class</strong></p>
<pre class="brush: java;">
package com.tutorial.enrollment.model;

import java.io.Serializable;

public class Student implements Serializable {
	private static final long serialVersionUID = 6981987850136048701L;

	private Long id;
	private String firstName;
	private String lastName;

	public Long getId() {
		return id;
	}
	public void setId(Long 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;
	}
}
</pre>
<p>The Student class follows the <a href="http://en.wikipedia.org/wiki/JavaBean">JavaBeans</a> specification with the use of private variables and public getters and setters method. Also, we tried to have the same properties in our class and columns in the student table. </p>
<p>Save Student.java in <span style="font-size:12px;"><strong>com.tutorial.enrollment/src/com/tutorial/enrollment/model</strong></span>.</p>
<p><a href="http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-2-getting-started">Part 2 – Create the Database and Persistent Class</a>  o0o <a href="http://josebobsantos.wordpress.com/2009/08/15/java-persistence-with-hibernate-part-4-create-the-mapping-file-and-configuration-file/">Part 4 – Create the Mapping File and Configuration File</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/josebobsantos.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/josebobsantos.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/josebobsantos.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/josebobsantos.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/josebobsantos.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/josebobsantos.wordpress.com/107/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/josebobsantos.wordpress.com/107/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/josebobsantos.wordpress.com/107/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=107&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-3-%e2%80%93-create-the-database-and-persistent-class/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37e46fd75e6e1bf1377c48499495f45d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">josebobsantos</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Persistence with Hibernate Part 2 &#8211; Getting Started</title>
		<link>http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-2-getting-started/</link>
		<comments>http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-2-getting-started/#comments</comments>
		<pubDate>Thu, 13 Aug 2009 17:15:49 +0000</pubDate>
		<dc:creator>josebobsantos</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Object Relational Mapping]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://josebobsantos.wordpress.com/?p=26</guid>
		<description><![CDATA[In Java Persistence with Hibernate Part 1 I&#8217;ve discussed the need for object/relational persistence and some things that Hibernate aims to answer. Hibernate has several modules which answer specific problems. The two most important modules to learn are Hibernate Core and Hibernate Annotations. Hibernate Core Hibernate Core for Java generates SQL for you, relieves you [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=26&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>In <a href="http://josebobsantos.wordpress.com/2009/08/12/java-persistence-with-hibernate-part-1/">Java Persistence with Hibernate Part 1</a> I&#8217;ve discussed the need for object/relational persistence and some things that Hibernate aims to answer. </p>
<p>Hibernate has several modules which answer specific problems. The two most important modules to learn are <a href="https://www.hibernate.org/344.html">Hibernate Core</a> and <a href="https://www.hibernate.org/397.html">Hibernate Annotations</a>.<br />
<span id="more-26"></span><br />
<strong>Hibernate Core</strong></p>
<blockquote><p>Hibernate Core for Java generates SQL for you, relieves you from manual JDBC result set handling and object conversion, and keeps your application portable to all SQL databases. Hibernate offers sophisticated query options, you can write plain SQL, object-oriented <a href="http://docs.jboss.org/hibernate/stable/core/reference/en/html/queryhql.html">HQL</a> (Hibernate Query Language), or create programatic Criteria and Example queries. &#8211; from hibernate.org</p></blockquote>
<p><strong>Hibernate Annotations</strong></p>
<blockquote><p>Hibernate, like all other object/relational mapping tools, requires metadata that governs the transformation of data from one representation to the other (and vice versa). As an option, you can now use <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/annotations.html">JDK 5.0 annotations</a> for object/relational mapping with Hibernate 3.2. You can use annotations in addition to or as a replacement of XML mapping metadata. &#8211; from hibernate.org</p></blockquote>
<p>To be able to use the power of Hibernate we only need Hibernate Core. But since Hibernate Core requires a lot of XML configurations, Hibernate Annotations is used to make development simpler and faster. To better understand this let&#8217;s create a simple Hibernate application.</p>
<p><span id="libraries" style="font-size:14px;"><strong>Getting Started</strong></span></p>
<p>First we need to prepare all the libraries for creating a Hibernate application. This could be easily done if you know build tools like Maven or Ant but I decided not to use them because it&#8217;s not a requirement and maybe some of you are not familiar with those tools.</p>
<ol>
<li>
   Download <a href="https://www.hibernate.org/6.html">Hibernate Core</a><br />
   Extract the zip file and you will get <strong>hibernate3.jar</strong>. <a href="http://i936.photobucket.com/albums/ad208/josebobsantos/hibernate1.gif">Image</a>
</li>
<li>
   Inside the lib folder there is a required folder and inside that you will find <strong>antlr-2.7.6.jar, commons-collections-3.1.jar, dom4j-1.6.1.jar, javassist-3.9.0.GA.jar and jta-1.1.jar</strong>. We will use a different version of sl4j. <a href="http://i936.photobucket.com/albums/ad208/josebobsantos/hibernate2.gif">Image</a>
</li>
<li>
   Download <a href="http://www.slf4j.org/dist/">sl4j-1.5.6.zip</a> and extract. We will need <strong>slf4j-api-1.5.6 and slf4j-simple-1.5.6</strong>
</li>
<li>
   Lastly we will need the JDBC driver for the database that we would be using, in this case MySQL 5.0. You may use other databases if you want just be sure know how to use them and configure them for database access from Java. <a href="http://dev.mysql.com/downloads/connector/j/5.0.html">Download the MySQL Connector/J 5.0</a>. We need <strong>mysql-connector-java-5.0.8-bin</strong>.
</li>
</ol>
<p><a href="http://josebobsantos.wordpress.com/2009/08/12/java-persistence-with-hibernate-part-1/">Java Persistence with Hibernate Part 1</a> o0o <a href="http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-3-%E2%80%93-create-the-database-and-persistent-class/">Java Persistence with Hibernate Part 3 &#8211; Create the Database and Persistent Class<br />
</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/josebobsantos.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/josebobsantos.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/josebobsantos.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/josebobsantos.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/josebobsantos.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/josebobsantos.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/josebobsantos.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/josebobsantos.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=26&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-2-getting-started/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37e46fd75e6e1bf1377c48499495f45d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">josebobsantos</media:title>
		</media:content>
	</item>
		<item>
		<title>Java Persistence With Hibernate Part 1</title>
		<link>http://josebobsantos.wordpress.com/2009/08/12/java-persistence-with-hibernate-part-1/</link>
		<comments>http://josebobsantos.wordpress.com/2009/08/12/java-persistence-with-hibernate-part-1/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 18:14:28 +0000</pubDate>
		<dc:creator>josebobsantos</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Object Relational Mapping]]></category>
		<category><![CDATA[Persistence]]></category>

		<guid isPermaLink="false">http://josebobsantos.wordpress.com/?p=6</guid>
		<description><![CDATA[Okay, first up on my list is Hibernate. I&#8217;ve used Hibernate with several projects already but since this is one of the two frameworks I will be teaching to my Java EE class, the other one is Spring MVC, I better read &#8220;Java Persistence With Hibernate 2nd Edition by Christian Bauer and Gavin King&#8221; and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=6&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Okay, first up on my list is <a href="https://www.hibernate.org/">Hibernate</a>. I&#8217;ve used Hibernate with several projects already but since this is one of the two frameworks I will be teaching to my <a href="http://phoenix-one.com/">Java EE class</a>, the other one is <a href="http://www.springsource.org/about">Spring MVC</a>, I better read <a href="http://www.amazon.com/Java-Persistence-Hibernate-Christian-Bauer/dp/1932394885">&#8220;Java Persistence With Hibernate 2nd Edition by Christian Bauer and Gavin King&#8221;</a> and have a refresher about the basics. With this said, I will try to explain things as simple as possible but you are expected to have a working knowledge of Java and SQL.<br />
<span id="more-6"></span><br />
<span style="font-family:georgia;font-size:16px;"><strong><em>Need for Object/Relational Persistence</em></strong></span></p>
<p>Persistence in Computer Science basically means the existence of data even after an application or program has ended. This can be done through the use of a relational database such as <a href="http://www.mysql.com/">MySQL</a> or <a href="http://www.microsoft.com/sqlserver/2008/en/us/default.aspx">SQL Server</a> with some stored procedures. </p>
<p>However, in creating applications we do not use relational databases by themselves (Imagine all of us creating queries and stored procedures just to save or retrieve data). We just integrate a database as a means to store data to our main application. Your application may be developed using Java or any other object-oriented language but this is where our problem starts.</p>
<p>Our application is an <a href="http://java.sun.com/docs/books/tutorial/java/concepts/index.html">Object-Oriented</a> language which is built around the idea of objects having states and behaviors while the database we are using is <a href="http://en.wikipedia.org/wiki/Relational_database">Relational</a> which is all about tables.<em> The problem is in translating those objects into a form that can be stored in a relational database</em>.(Paradigm mismatch: <a href="http://www.objectmatter.com/vbsf/docs/maptool/ormapping.html">Object Relational Mapping</a>)</p>
<p>Another concern is that <a href="http://java.sun.com/docs/books/tutorial/java/javaOO/classes.html">Java</a> has a different syntax than <a href="http://www.w3schools.com/sql/sql_intro.asp">SQL</a>(the base language being used by relational databases). Well, Java has <a href="http://java.sun.com/docs/books/tutorial/jdbc/index.html">JDBC</a> but is it enough? Do we just hard-code all of our SQL commands?</p>
<p>Lastly, different relational database management systems(RDBMS) uses different extensions of SQL, meaning they may have different syntax for several SQL commands. This poses a problem when you are trying to migrate from one RDBMS to another. Let&#8217;s say you used MySQL as your RDBMS for development and you had all your SQL commands hand-coded within your application. However, before deploying the application your client tells you that they would be using <a href="http://www.oracle.com/index.html">Oracle </a>instead. You think that there&#8217;s no problem, since you used JDBC you just need to change some configurations regarding the driver used and migrate the MySQL tables to Oracle. But lo and behold when you deployed the application some part of it was not working. Most probably this is because some of your hand-coded MySQL commands have different syntax in Oracle.</p>
<blockquote><p>
Hibernate is an ambitious project that aims to be a complete solution to the problem of managing persistent data in Java. It mediates the application’s interaction with a relational database, leaving the developer free to concentrate on the business problem at hand. &#8211; from the book &#8220;Java Persistence With Hibernate&#8221;</p></blockquote>
<p>There are other issues regarding Object Relational Mapping but I guess with the above explanation you already have a basic idea of the importance of Object/Relational persistence.</p>
<p><a href="http://josebobsantos.wordpress.com/2009/08/14/java-persistence-with-hibernate-part-2-getting-started/">Java Persistence With Hibernate Part 2 &#8211; Getting Started</a></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/josebobsantos.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/josebobsantos.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/josebobsantos.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/josebobsantos.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/josebobsantos.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/josebobsantos.wordpress.com/6/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/josebobsantos.wordpress.com/6/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/josebobsantos.wordpress.com/6/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=josebobsantos.wordpress.com&amp;blog=8964794&amp;post=6&amp;subd=josebobsantos&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://josebobsantos.wordpress.com/2009/08/12/java-persistence-with-hibernate-part-1/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/37e46fd75e6e1bf1377c48499495f45d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">josebobsantos</media:title>
		</media:content>
	</item>
	</channel>
</rss>
