<?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>JavaBeat &#187; JBoss</title>
	<atom:link href="http://www.javabeat.net/category/web-servers/jboss-web-servers/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Thu, 23 May 2013 01:30:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Developing Applications with JBoss, Hibernate and EJB 3.0</title>
		<link>http://www.javabeat.net/2010/02/developing-applications-with-jboss-and-hibernate/</link>
		<comments>http://www.javabeat.net/2010/02/developing-applications-with-jboss-and-hibernate/#comments</comments>
		<pubDate>Sun, 14 Feb 2010 00:18:55 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Hibernate]]></category>
		<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1948</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>JBoss AS 5 DevelopmentThe JBoss Application Server is a Java EE-certified platform for developing and deploying Java Enterprise applications. JBoss Application Server provides the full range of J2EE 1.5 features as well as extended Enterprise services including clustering, caching, and persistence. This book will show Java EE developers how to develop their applications using the JBoss Application Server. It [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p><center><strong>JBoss AS 5 Development</strong></center>The JBoss Application Server is a Java EE-certified platform for developing and deploying Java Enterprise applications. JBoss Application Server provides the full range of J2EE 1.5 features as well as extended Enterprise services including clustering, caching, and persistence. This book will show Java EE developers how to develop their applications using the JBoss Application Server. It covers topics such as:</p>
<ul>
<ul>
<li>Setting up a development environment</li>
</ul>
</ul>
<ul>
<ul>
<li>Customization</li>
</ul>
</ul>
<ul>
<ul>
<li>Java EE programming modules</li>
</ul>
</ul>
<ul>
<ul>
<li>Clustering</li>
</ul>
</ul>
<ul>
<ul>
<li>Security</li>
</ul>
</ul>
<p>All these features will be explored by developing sample and intuitive applications built using the friendly interface of Eclipse and JBoss Tools.</p>
<p><strong>What This Book Covers</strong></p>
<p>Chapter 1: <i>Installing Core Components</i> covers the installation of the key components that will be needed throughout the rest of the book. The installation process will be completed by using intuitive wizards that will lead even inexperienced users through it.</p>
<p>Chapter 2: <i>What&#8217;s New in JBoss AS 5.0</i> introduces the reader to the most significant changes brought by release 5.0 of the application server. The new server directory tree is analyzed in detail and possible variants in the server configuration are discussed in the latter part of this chapter.</p>
<p>Chapter 3: <i>Customizing JBoss Services</i> discusses the core configuration of the application server. The highlights of it include an introduction to JBoss AS monitoring services, the inner details about JBoss thread pool, how to configure logging services, and a detailed description of the transaction and Datasource service.</p>
<p>Chapter 4: <i>Developing EJB 3 Session Bean</i> introduces the reader to some concrete Java EE programming examples developed on JBoss AS 5. The focus of this chapter is on EJB 3 session Beans, including a section about their configuration for optimal results.</p>
<p>Chapter 5: <i>Developing JPA Entities</i> covers the development of an example based on the Java Persistence API (JPA). Here, we introduce an enterprise application named the Appstore, which will be a central theme of this book.</p>
<p>Chapter 6: <i>Creating a Web Application</i> is about developing and configuring web applications on JBoss AS 5.0 using the JSF cutting-edge technology. In the first part of this chapter we will enhance the Appstore Enterpirse application by adding a web layer to<br />
it. In the latter part, we explain in detail how to properly configure JBoss Web Server.</p>
<p>Chapter 7: <i>Developing Applications with JBoss Messaging Service</i> discusses JBoss Messaging provider by giving a short introduction to the new messaging system. The chapter then helps us set up some proof of concept programming examples.</p>
<p>Chapter 8: <i>Developing Applications with JBoss and Hibernate</i> covers the de facto standard object relational mapping tool, Hibernate, showing how to quickly set up a Hibernate project using the facilities provided by the JBoss tools interface.</p>
<p>Chapter 9: <i>Managing JBoss AS</i> covers the Java Management Extension (JMX), which still plays a vital role in the application server infrastructure. The chapter includes many examples that show how to write traditional MBeans services and the new POJO Services.</p>
<p>Chapter 10: <i>Developing Applications with JBoss Web Services</i> focuses on the JBoss Web Service implementation, JBossWS, showing how to create, deploy, and test Web Services on JBoss AS along with some advanced concepts such as Handler chains and SOAP debugging.</p>
<p>Chapter 11: <i>Clustering JBoss AS</i> covers the facts about JBoss AS clustering configuration, moving from cluster basics to detailed configuration of the individual services of the application server.</p>
<p>Chapter 12: <i>Developing a Clustered Application</i> continues the journey in the clustering arena by adding some concrete examples based on the abstract concepts covered in the earlier chapter.</p>
<p>Chapter 13: <i>JBoss AS Security</i> provides a systematic guide to JBoss security framework and the cryptographic interfaces available in the Java EE framework. This supplies the basis for concrete examples, which are delivered in the next chapter.</p>
<p>Chapter 14: <i>Securing JBoss AS Applications</i> continues the in-depth exploration of the JBoss security framework, adding concrete programming examples applied on the EJB and Web Services technologies.</p>
<h2 style="text-align: center;"><span style="text-decoration: underline;"><span style="color: #000080; text-decoration: underline;">Developing Applications with JBoss and Hibernate</span></span></h2>
<pre class="brush: java; title: ; notranslate">
	&lt;i&gt;Hibernation is a state of regulated hypothermia undergone by some animals to
	conserve energy during the winter&lt;/i&gt;. – Wikipedia</pre>
<p>In this chapter, we will introduce Hibernate, which is the <i>de facto</i> standard object-relational mapping framework for Java applications. The Hibernate galaxy is quite large and needs a book of its own to be fully explored. Our mission will be to take over one sector of this galaxy, especially where Hibernate applications are managed by JBoss AS.</p>
<p>In this chapter, we will cover the following topics:</p>
<ul>
<ul>
<li>A short introduction to Hibernate</li>
</ul>
</ul>
<ul>
<ul>
<li>Setting up our proof of concept for the Hibernate project</li>
</ul>
</ul>
<ul>
<ul>
<li>Reverse engineering a database schema into Hibernate POJOs and mapping files</li>
</ul>
</ul>
<ul>
<ul>
<li>Deploying the application to JBoss AS</li>
</ul>
</ul>
<ul>
<ul>
<li>Comparing the Hibernate technology with EJB 3 persistence (JPA)</li>
</ul>
</ul>
<h2>Introducing Hibernate</h2>
<p>Hibernate provides a bridge between the database and the application by persisting application objects in the database, rather than requiring the developer to write and maintain lots of code to store and retrieve objects.</p>
<p>The main configuration file, hibernate.cfg.xml, specifies how Hibernate obtains database connections, either from a JNDI DataSource or from a JDBC connection pool. Additionally, the configuration file defines the persistent classes, which are backed by mapping definition files.</p>
<p>This is a sample hibernate.cfg.xml configuration file that is used to handle connections to a MySQL database, mapping the com.sample.MySample class.</p>
<pre class="brush: java; title: ; notranslate">	&lt;hibernate-configuration&gt;
		&lt;session-factory&gt;
			&lt;property name=&quot;connection.username&quot;&gt;user&lt;/property&gt;
			&lt;property name=&quot;connection.password&quot;&gt;password&lt;/property&gt;
			&lt;property name=&quot;connection.url&quot;&gt;
				jdbc:mysql://localhost/database
			&lt;/property&gt;
			&lt;property name=&quot;connection.driver_class&quot;&gt;
				com.mysql.jdbc.Driver
			&lt;/property&gt;
			&lt;property name=&quot;dialect&quot;&gt;
				org.hibernate.dialect.MySQLDialect
			&lt;/property&gt;
			&lt;mapping resource=&quot;com/sample/MyClass.hbm.xml&quot;/&gt;
		&lt;/session-factory&gt;
	&lt;/hibernate-configuration&gt;</pre>
<p>From our point of view, it is important to know that Hibernate applications can coexist in both the <b>managed</b> environment and the <b>non-managed</b> environment. An application server is a typical example of a managed environment that provides services to hosting applications, such as connection pooling and transaction.</p>
<p>On the other hand, a non-managed application refers to standalone applications, such as Swing Java clients that typically lack any built-in service.</p>
<p>In this chapter, we will focus on managed environment applications, installed on JBoss Application Server. You will not need to download any library to your JBoss installation. As a matter of fact, JBoss persistence layer is designed around Hibernate API, so it already contains all the core libraries.</p>
<h2>Creating a Hibernate application</h2>
<p>You can choose different strategies for building a Hibernate application. For example, you could start building Java classes and map files from scratch, and then let Hibernate generate the database schema accordingly. You can also start from a database schema<br />
and reverse engineer it into Java classes and Hibernate mapping files. We will choose the latter option, which is also the fastest. Here&#8217;s an overview of our application.</p>
<p>In this example, we will design an employee agenda divided into departments. The persistence model will be developed with Hibernate, using the reverse engineering facet of JBoss tools. We will then need an interface for recording our employees and<br />
departments, and to query them as well.</p>
<p>The web interface will be developed using a simple <b>Model-View-Controller (MVC) </b>pattern and basic JSP 2.0 and servlet features.</p>
<p>The overall architecture of this system resembles the AppStore application that has been used to introduce JPA. As a matter of fact, this example can be used to compare the two persistence models and to decide which option best suits your project needs. We have added a short section at the end of this example to stress a few important points about this choice.</p>
<h2>Setting up the database schema</h2>
<p>As our first step, we are going to create the necessary tables for our example. Launch a MySQL client and issue the following DDL:</p>
<pre class="brush: java; title: ; notranslate">	CREATE schema hibernate;
	GRANT ALL PRIVILEGES ON hibernate.* TO 'jboss'@'localhost' WITH GRANT
	OPTION;
	CREATE TABLE `hibernate`.`department` (
		`department_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
		`department_name` VARCHAR(45) NOT NULL,
		PRIMARY KEY (`department_id`)
	)
	ENGINE = InnoDB;
	CREATE TABLE `hibernate`.`employee` (
		`employee_id` INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
		`employee_name` VARCHAR(45) NOT NULL,
		`employee_salary` INTEGER UNSIGNED NOT NULL,
		`employee_department_id` INTEGER UNSIGNED NOT NULL,
		PRIMARY KEY (`employee_id`),
		CONSTRAINT `FK_employee_1` FOREIGN KEY `FK_employee_1` (`employee_
	department_id`)
		REFERENCES `department` (`department_id`)
		ON DELETE CASCADE
		ON UPDATE CASCADE
	)
	ENGINE = InnoDB;</pre>
<p>With the first <b>Data Definition Language (DDL)</b> command, we have created a schema named Hibernate that will be used to store our tables. Then, we have assigned the necessary privileges on the Hibernate schema to the user jboss (created in Chapter 5, <i>Developing JPA Entities</i>).</p>
<p>Finally, we created a table named department that contains the list of company units, and another table named employee that contains the list of workers. The employee table references the department with a foreign key constraint.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-1.jpg"><img class="aligncenter size-full wp-image-6631" alt="jboss-hibernate-1" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-1.jpg" width="447" height="195" /></a></center></p>
<h2>A new Eclipse project</h2>
<p>Now start Eclipse. You don&#8217;t have a specific project for Hibernate applications, so a utility project (that simply packs the classes in an archive) will be enough. You can reach this option from the menu by going to <b>New | Other | Java EE | Utility Project</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-2.jpg"><img class="aligncenter  wp-image-6632" alt="jboss-hibernate-2" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-2.jpg" width="431" height="402" /></a></center>Name the project <b>HibernateProject</b> and target it to <b>JBoss AS 5.0 Runtime</b>. You can leave the default JBoss AS configuration and hit <b>Finish</b>.</p>
<p>Now, we are going to unleash the full potential of <b>Hibernate tools</b>. Select from the menu <b>New | Other | Hibernate | Hibernate Configuration File</b>. The Hibernate configuration contains all of the details for wiring your application to the database. You will be asked for the name and the parent folder of the configuration file. Accept the default hibernate.cfg.xml at the root of your project.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-3.jpg"><img class="aligncenter  wp-image-6633" alt="jboss-hibernate-3" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-3.jpg" width="437" height="272" /></a></center>Next , insert the details of your Hibernate configuration. Choose a name for your session factory, which will contain your MySQL connection facets. Remember to check the fl ag <b>Create a console configuration</b>, so that the wizard will complete the console configuration as the next step.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-4.jpg"><img class="aligncenter  wp-image-6634" alt="jboss-hibernate-4" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-4.jpg" width="409" height="357" /></a></center>A <b>console configuration</b> describes how the Hibernate plugin should interact with Hibernate and what configuration files (including the classpath) are needed to load the POJOs, JDBC drivers, and so on. This step is required to make use of query prototyping, reverse engineering, and code generation.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-5.jpg"><img class="aligncenter  wp-image-6635" alt="jboss-hibernate-5" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-5.jpg" width="456" height="460" /></a></center>The console wizard will look at the current selection in the IDE and will try to autodetect the settings, which you can approve or modify to suit your needs. For example, you don&#8217;t need to enter the <b>Configuration file</b> or the <b>Property file</b> if you have just one in your project; Eclipse will select it automatically.</p>
<p>One important selection is the <b>Type</b> option that lets you choose between the <b>Core </b>hibernate configuration (Java classes backed by mapping files), <b>Annotations</b>, or even <b>JPA</b> annotations. We will leave the selected <b>Core</b> option.</p>
<p>Before clicking <b>Finish</b>, select <b>MySQL (InnoDB)</b> as <b>Database dialect</b> in the <b>Options </b>tab. No other changes are required.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-6.jpg"><img class="aligncenter  wp-image-6636" alt="jboss-hibernate-6" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-6.jpg" width="446" height="338" /></a></center>Now verify that you have successfully linked to Hibernate by switching to <b>Hibernate Configuration</b>. This view will be composed by a tree of three objects: <b>Configuration, Session Factory,</b> and <b>Database</b>. Choose Database and verify that it expands correctly to show the database tables of your schema.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-7.jpg"><img class="aligncenter size-full wp-image-6637" alt="jboss-hibernate-7" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-7.jpg" width="298" height="263" /></a></center>If you fail to browse the database schema, check that you have correctly set up your Hibernate configuration.</p>
<h2>Reversing your schema into Java classes</h2>
<p>The next move will be reversing our database schema into Java classes and mapping files. This powerful feature is available from the menu: <b>File | New | Hibernate |Hibernate Reverse Engineering file</b>. You can place this file in a convenient location for your project and choose a name for it. The default name proposed is hibernate.reveng.xml, which looks rather the tile of another fiction movie from G. Lucas.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-8.jpg"><img class="aligncenter  wp-image-6638" alt="jboss-hibernate-8" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-8.jpg" width="367" height="191" /></a></center>On the next page, select your <b>Console configuration</b> and choose the tables that will be included in your reverse engineering process. (Hint: You have to hit <b>Refresh</b> first to show the database schema and then click <b>Include&#8230;.)</b></p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-9.jpg"><img class="aligncenter  wp-image-6639" alt="jboss-hibernate-9" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-9.jpg" width="421" height="236" /></a></center>What Eclipse has just created for you is a file named hibernate.reveng.xml that should resemble the following code snippet:</p>
<pre class="brush: java; title: ; notranslate">	&lt;hibernate-reverse-engineering&gt;
		&lt;table-filter match-catalog=&quot;hibernate&quot; match-name=&quot;department&quot;/&gt;
		&lt;table-filter match-catalog=&quot;hibernate&quot; match-name=&quot;employee&quot;/&gt;
	&lt;/hibernate-reverse-engineering&gt;</pre>
<p>If you are smart at noticing variations, you might have discovered a new icon in your toolbar. This is your gateway to the reverse engineering process. (Notice: this icon is visible only in the Hibernate Perspective, you will not be able to find it anywhere else.)</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-10.jpg"><img class="aligncenter  wp-image-6640" alt="jboss-hibernate-10" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-10.jpg" width="451" height="62" /></a></center>Click on Hibernate&#8217;s down arrow icon and select <b>Hibernate Code Generation Configurations</b>. In the next dialog, you will first have to create a new <b>Hibernate Code Generation Configuration</b> that will contain all the details of your reverse engineering process. Click on the <b>New</b> button located in the left corner of the wizard.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-11.jpg"><img class="aligncenter  wp-image-6641" alt="jboss-hibernate-11" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-11.jpg" width="456" height="200" /></a></center>Now, select your brand new configuration and carefully choose the following options. First, wire the <b>Console configuration</b> to your project (HibernateProject). Then, choose an output directory for your generated files. We would suggest you to point to your src folder. (Be aware that existing files will be overwritten, that&#8217;s why I just said you have to be <i>careful</i>!)</p>
<p>Just below, you will find the checkbox <b>Reverse engineer from JDBC Connection</b>. If enabled, the tools will reverse engineer the available database using the connection information in the selected Hibernate Console configuration. Check this option and enter the package name for the generated classes, which will be <b>com.packtpub. hibernate</b>. Leave the other text fields to the defaults and move to the tab <b>Exporters</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-12.jpg"><img class="aligncenter  wp-image-6642" alt="jboss-hibernate-12" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-12.jpg" width="365" height="341" /></a></center><br />
The <b>Exporters</b> tab menu is used to specify which type of code should be generated. Each selection represents an Exporter that is responsible for generating the code, hence the name.</p>
<p>In the upper area of the dialog, you will notice an interesting checkbox named <b>Generate EJB 3 annotations</b>. We will return to this useful option later. At the moment, what we need is just to check the <b>Domain code and Hibernate XML Mappings </b>options, which will generate the Java POJOs and mapping files respectively.</p>
<p style="text-align: center;"><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-13.jpg"><img class=" wp-image-6643 aligncenter" alt="jboss-hibernate-13" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-13.jpg" width="427" height="375" /></a></p>
<p>It took a bit of time to complete all of these steps; however, now your Java classes and configuration files are handy and waiting to be packaged.</p>
<h2>Adding Hibernate configuration to your project</h2>
<p>The advantage of embedding the Hibernate application in JBoss AS is that you can expose <b>Hibernate SessionFactory</b> through a JN DI tree and modify its configuration at runtime.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>This is indeed a great configuration advantage; before the new release of JBoss AS, you had to delegate to an MBean the creation of the Hibernate SessionFactory and its exposure through JNDI.</p>
<p>For example, if you wanted to configure a SessionFactory at the naming context hibernate/SessionFactory, you would have to package your Hibernate application with a file named xxx-service.xml in the META-INF folder. Here&#8217;s a sample of it:</p>
<pre class="brush: java; title: ; notranslate">	&lt;server&gt;
		&lt;mbean code=&quot;org.jboss.hibernate.jmx.Hibernate&quot;
			name=&quot;jboss.har:service=Hibernate&quot;&gt;
			&lt;attribute name=&quot;DatasourceName&quot;&gt;java:/ MySqlDS&lt;/attribute&gt;
			&lt;attribute name=&quot;Dialect&quot;&gt;
				org.hibernate.dialect.MySQLDialect
			&lt;/attribute&gt;
			&lt;attribute name=&quot;SessionFactoryName&quot;&gt;
				java:/hibernate/SessionFactory
			&lt;/attribute&gt;
			&lt;attribute name=&quot;CacheProviderClass&quot;&gt;
				org.hibernate.cache.HashtableCacheProvider
			&lt;/attribute&gt;
		&lt;/mbean&gt;
	&lt;/server&gt;</pre>
<p>This configur ation is still valid for pre 5.0 releases of JBoss AS. With the introduction of the new <b>Virtual Deployment Framework (VDF)</b>, you now have to provide your <b>SessionFactory</b> configuration using the Hibernate XML schema. For example, if you want to link your SessionFactory to your MySQL database, you have to add the following service-hibernate.xml. (Be aware, the suffix is -hibernate.xml and not –service.xml.)</p>
<pre class="brush: java; title: ; notranslate">	&lt;hibernate-configuration xmlns=&quot;urn:jboss:hibernate-deployer:1.0&quot;&gt;
		&lt;session-factory name=&quot;java:/hibernate/SessionFactory&quot;
			bean=&quot;jboss.test.har:service=Hibernate,
			testcase=TimersUnitTestCase&quot;&gt;
			&lt;property name=&quot;datasourceName&quot;&gt;java:/MySqlDS&lt;/property&gt;
			&lt;property name=&quot;dialect&quot;&gt;
				org.hibernate.dialect.MySQLDialect
			&lt;/property&gt;
			&lt;depends&gt;jboss:service=Naming&lt;/depends&gt;
			&lt;depends&gt;jboss:service=TransactionManager&lt;/depends&gt;
		&lt;/session-factory&gt;
	&lt;/hibernate-configuration&gt;</pre>
<p>The preceding configuration file needs to be stored in the META-INF folder of your <b>Hibernate archive (HAR)</b> file. The structure of the updated project from the <b>Package Explorer</b> is as shown in the following snapshot:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-14.jpg"><img class="aligncenter size-full wp-image-6644" alt="jboss-hibernate-14" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-14.jpg" width="478" height="424" /></a></center></p>
<h2>Adding a web client to your project</h2>
<p>There are seve ral ways to test our Hibernate application. The simplest of all is adding a web application, which is packaged in an Enterprise application along with the Hibernate application. Create a new dynamic web project named HibernateWeb.</p>
<p>The first step, before adding servlets and JSPs is linking the HibernateProject libraries to your web application, otherwise, you will not be able to reference the Hibernate POJOs. Right-click on your project and select <b>Properties</b>. Reach the <b>Java Build Path </b>option and select the tab <b>Projects</b>. From there add <b>HibernateProject</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-15.jpg"><img class="aligncenter  wp-image-6645" alt="jboss-hibernate-15" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-15.jpg" width="458" height="196" /></a></center>Let&#8217;s move on. This project will contain a main servlet that acts as a controller, and a few JPSs for the client view. We will start by adding com.packtpub.hibernateWeb. HibernateServlet to our project.</p>
<p>In the following snippet, you can see the core section of the servlet. Here, we will not detail the Controller logic, which is straightforward if you have some rudiments of the MVC pattern; rather we want to highlight the most interesting part of it, which is how to query and persist Hibernate objects.</p>
<pre class="brush: java; title: ; notranslate">	public class HibernateServlet extends HttpServlet {
		private SessionFactory getSessionFactory() {
			return (SessionFactory)getServletContext().
			getAttribute(&quot;sessionFactory&quot;);
		}
		public void init() { [1]
			if (getSessionFactory() != null) {
				return;
			}
			InitialContext ctx;
			try {
				ctx = new InitialContext();
				&lt;b&gt;factory = (SessionFactory)ctx.
					lookup(&quot;java:/hibernate/SessionFactory&quot;);
				getServletContext().setAttribute(&quot;sessionFactory&quot;, factory);&lt;/b&gt;
			}
			catch (NamingException e) {
				e.printStackTrace();
			}
		}
		private String saveEmployee(HttpServletRequest request) {
			Session hsession=null;
			String name=request.getParameter(&quot;name&quot;);
			String salary=request.getParameter(&quot;salary&quot;);
			String departmentId=request.getParameter(&quot;departmentId&quot;);
			try {
				hsession = getSessionFactory().openSession();
				hsession.beginTransaction();
				&lt;b&gt;Query query = hsession.createQuery(&quot;from Department d where
					d.departmentId = :departmentId&quot;); [2]&lt;/b&gt;
				query.setInteger(&quot;departmentId&quot;, new Integer(departmentId));
				Department dep = (Department) query.uniqueResult();
				Employee emp = new Employee();
				emp.setDepartment(dep);
				emp.setEmployeeName(name);
				emp.setEmployeeSalary(Integer.parseInt(salary));
				&lt;b&gt;hsession.save(emp); [3]&lt;/b&gt;
				hsession.getTransaction().commit();
			}
			catch (Exception e) {
				// TODO Auto-generated catch block e.printStackTrace();
				hsession.getTransaction().rollback();
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
			return employeeList(request);
		}
		private String employeeList(HttpServletRequest request) {
			Session hsession=null;
			Department dep;
			try {
				hsession = getSessionFactory().openSession();
				&lt;b&gt;Query query = hsession.createQuery(&quot;select p from Employee p
					join fetch p.department c&quot;); [4]&lt;/b&gt;
				List &lt;Employee&gt;list = query.list();
				request.setAttribute(&quot;employee&quot;, list);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
			return &quot;/listEmployees.jsp&quot;;
		}
		private String saveDepartment(HttpServletRequest request) {
			String depName=request.getParameter(&quot;depName&quot;);
			Session hsession=null;
			Department dep;
			try {
				hsession = getSessionFactory().openSession();
				hsession.beginTransaction();
				dep = new Department();
				dep.setDepartmentName(depName);
				&lt;b&gt;hsession.save(dep); [5]&lt;/b&gt;
				hsession.getTransaction().commit();
			}
			catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				hsession.getTransaction().rollback();
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
			return employeeList(request);
		}
	}</pre>
<p>As you can see from the preceding code, we recover the SessionFactory from the JNDI tree in the init() <b>[1]</b> method of the servlet. Instances of SessionFactory are thread-safe and typically shared throughout an application, so we store it in the ServletContext and share it among all servlet instances.</p>
<p>The SessionFactory is subsequently used to start a Hibernate session, which is not thread-safe and should only be used for a single transaction or unit of work in an application.</p>
<p>In order to store our Employee, in the saveEmployee method, we first retrieve the corresponding Department from our schema <b>[2]</b>, and finally the Employee is saved <b>[3]</b> and the transaction is committed.</p>
<p>The list of employees is fetched by the employeeList method. Notice we are using a join fetch statement to retrieve all the employees <b>[4]</b>, which will be routed to the listEmployees.jsp view. Why? The answer is that with the default fetch mode (Lazy), once the Hibernate session is closed, the client will not be able to navigate through the department field of the Employee. The common solution to this issue is switching to the EAGER fetch mode that reads the related fields (in our case department) in memory, as soon as we query the Employee table.</p>
<p>You have more than one option to achieve this. One possible solution, if you don&#8217;t want to change the default fetch mode for the Employee table, is to build an <i>ad hoc</i> query that forces Hibernate to read also those fields that are in relation with the Employee table.</p>
<pre class="brush: java; title: ; notranslate">	&quot;select p from Employee p join fetch p.department c&quot;</pre>
<p>If you prefer to use the XML class files to configure the fetch mode, you can also change the lazy=&#8221;true&#8221; attribute in the employee-department relationship.</p>
<p>The last method, saveDepartment <b>[5]</b> takes care to persist a new Department in the corresponding table. We complete our excursus on the web tier with the listEmployees.jsp that is used to display a tabular view of the employees:</p>
<pre class="brush: java; title: ; notranslate">	&lt;b&gt;&lt;%@ taglib uri=&quot;http://java.sun.com/jsp/jstl/core&quot; prefix=&quot;c&quot; %&gt;&lt;/b&gt;
	&lt;html&gt;
		&lt;script language=&quot;JavaScript&quot;&gt;
			function doSubmit(url) {
				document.module.action = url;
				document.module.submit();
			}
		&lt;/script&gt;
		&lt;body&gt;
			&lt;table border=&quot;1&quot;&gt;
				&lt;tr&gt;
					&lt;th&gt;Name&lt;/th&gt;
					&lt;th&gt;Salary&lt;/th&gt; &lt;TH&gt;department&lt;/th&gt;
				&lt;/tr&gt;
				&lt;b&gt;&lt;c:forEach items=&quot;${employee}&quot; var=&quot;emp&quot;&gt;
					&lt;tr&gt;
						&lt;td&gt; &lt;c:out value=&quot;${emp.employeeName}&quot;/&gt; &lt;/td&gt;
						&lt;td&gt; &lt;c:out value=&quot;${emp.employeeSalary}&quot;/&gt;&lt;/td&gt;
						&lt;td&gt; &lt;c:out value=&quot;${emp.department.departmentName}&quot;/&gt;&lt;/td&gt;
					&lt;/tr&gt;
				&lt;/c:forEach&gt;&lt;/b&gt;
			&lt;/table&gt;
			&lt;form name=&quot;module&quot; method=&quot;POST&quot;&gt;
				&lt;input type=&quot;button&quot; value =&quot;New Employee&quot;
					onClick=&quot;doSubmit('actionServlet?op=newEmployee')&quot;&gt;
				&lt;input type=&quot;button&quot; value =&quot;New Department&quot;
					onClick=&quot;doSubmit('actionServlet?op=newDepartment')&quot;&gt;
			&lt;/form&gt;
		&lt;/body&gt;
	&lt;/html&gt;</pre>
<p>This page uses JSP 2.0 <b>Expression Language (EL)</b> to iterate through the list of employees, as highlighted in the last code snippet. We have also highlighted the taglib directive, at the beginning of the page. This directive will be used to resolve the JSTL core set of libraries that ships with JBoss AS in the server/xxx/deploy/ jbossweb.sar/jstl.jar library. (Eclipse does not contain references to this library when you create a web project; you have to add jstl.jar to your build path, otherwise Eclipse will mark it as an error. However, that&#8217;s only a visual annoyance because the JBoss web container has got everything it needs to run JSTL.)</p>
<p>The complete web application is available on the Packtpub website (http://www.packtpub.com) and includes two additional JSPs for entering the employee (newEmployee.jsp) and department (newDepartment.jsp) data, plus one placeholder index.jsp that merely forwards to the <b>HibernateServlet</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-16.jpg"><img class="aligncenter size-full wp-image-6646" alt="jboss-hibernate-16" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-16.jpg" width="387" height="306" /></a></center></p>
<h2>Packaging and deploying the application</h2>
<p>Your enterprise application is complete. We need to package it in an EAR archive so that the web application will be able to interact with the Hibernate POJOs. Create a new <b>Enterprise Application</b> project from the Java EE folder. You will be prompted to select the projects that will be included as modules. Select both the <b>HibernateProject</b> and the web application <b>HibernateWeb</b>.</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-17.jpg"><img class="aligncenter size-full wp-image-6647" alt="jboss-hibernate-17" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-17.jpg" width="503" height="537" /></a></center> If you have ever worked with JBoss AS and Hibernate, then you might argue that right now something is missing. You&#8217;re indeed right. Before release 5.0 of the JBoss Application Server, Hibernate classes and mapping files had to be packaged in a JBoss AS custom .har archive. The suffix was determinant, as JBoss AS was able to classify the package as a Hibernate resource.</p>
<p>As HAR archives are not Java EE standard components, you have to declare it in a JBoss AS-specific configuration file named jboss-app.xml that sits in the META-INF folder of our EAR.</p>
<pre class="brush: java; title: ; notranslate">	&lt;!DOCTYPE jboss-app PUBLIC &quot;-//JBoss//DTD J2EE Application 1.5//EN&quot;
		&quot;http://www.jboss.org/j2ee/dtd/jboss-app_5_0.dtd&quot;&gt;
		&lt;jboss-app&gt;
			&lt;module&gt;
				&lt;har&gt;HibernateApplication.har&lt;/har&gt;
			&lt;/module&gt;
		&lt;/jboss-app&gt;</pre>
<p>While this approach is still advisable if you want to grant backward compatibility to your applications, with release 5.0 of the Application Server you now have a handy quicker solution. As the new VFS of JBoss AS is able to detect the nature of your application by scanning deployment descriptors, it&#8217;s enough to pack your Hibernate application in a plain <b>Java ARchive (JAR)</b>. JBoss AS will discover the .hbm.xml mapping files and look for the corresponding Java classes. If successful, the package will be deployed as a Hibernate application straightaway.</p>
<p>The corollary of this theorem is that you can leave out, as well, the JBoss AS configuration file jboss-app.xml, which is not necessary any more. The only update required is to your application.xml, where your Hibernate application is declared as a Java module in order to make it available to other enterprise modules.</p>
<pre class="brush: java; title: ; notranslate">	&lt;application&gt;
		&lt;module&gt;
			&lt;web&gt;
				&lt;web-uri&gt;HibernateWeb.war&lt;/web-uri&gt;
				&lt;context-root&gt;HibernateWeb&lt;/context-root&gt;
			&lt;/web&gt;
		&lt;/module&gt;
		&lt;b&gt;&lt;module&gt;
			&lt;java&gt;HibernateProject.jar&lt;/java&gt;
		&lt;/module&gt;&lt;/b&gt;
	&lt;/application&gt;</pre>
<p>This is how your Enterprise ARchive should look like before deploying it:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-18.jpg"><img class="aligncenter size-full wp-image-6648" alt="jboss-hibernate-18" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-18.jpg" width="388" height="288" /></a></center> Now deploy your application in the usual way, by adding the project to JBoss AS projects and then choosing <b>Full Publish</b>. The application server will then produce a few log pages; if the binding of classes is successful, you will find the following among your logs:</p>
<p><b>16:46:18,949 INFO [HbmBinder] Mapping class: com.packtpub.hibernate.</b></p>
<p>Employee -&gt;employee</p>
<p><b>16:46:19,261 INFO [HbmBinder] Mapping class: com.packtpub.hibernate.</b></p>
<p>Department -&gt; department</p>
<p><b>16:46:19,277 INFO [HbmBinder] Mapping collection: com.packtpub.hibernate.</b></p>
<p>Department.employees -&gt; employee</p>
<p>In order to test your application, simply recall your JSP default page, using the HibernateWeb context. In our example:</p>
<p>http://localhost:8080/HibernateWeb/</p>
<h2>Using the wizard to generate EJB 3</h2>
<p>Hibernate tool capabilities are not limited to Hibernate programming. By using the reverse engineering option, you can also generate EJB 3.0 classes in a matter of seconds. Recall the <b>Reverse Engineering Configuration:</b></p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-19.jpg"><img class="aligncenter  wp-image-6649" alt="jboss-hibernate-19" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-19.jpg" width="502" height="441" /></a></center> If you Check the <b>Generate EJB 3 annotations</b> checkbox along with <b>Domain code</b>, then the outcome of your reverse engineering process would be simple Java classes with entity annotations. That&#8217;s a huge saving of time, especially if your database schema is rather complex. You can still adjust your entity beans to your needs once they are generated.</p>
<h2>Hibernate and EJB: Friends or opponents?</h2>
<p>In Chapter 4, we introduced the EJB programming model, so at this stage, you might wonder when it&#8217;s more appropriate to use EJB from your projects and when it&#8217;s better to stay on the Hibernate framework.</p>
<p>The premise of this debate is that EJB and Hibernate are not fully comparable because they are semantically different. EJBs live in a container, which provides services, such as transactions, concurrent access control, security, instance pooling,and others. On the other hand, Hibernate is classified as an <b>object-relational mapping tool</b> and it is independent from a server container.</p>
<p>So, if comparing EJB and Hibernate is technically a mistake, you can actually compare the <b>Java Persistence API</b> and Hibernate, which are, in some ways, two <i>antagonist</i> technologies. The most important factor, which is in favor of JPA, is that it is a standard. Using industry-standard components allows the business comparatively more fl exibility when it&#8217;s necessary to change its business model, to reorchestrate itself, and to collaborate dynamically.</p>
<p>Technically speaking, it is also important to stress that an EJB-centric approach is the appropriate implementation technology for two types of applications:</p>
<ul>
<ul>
<li>Applications that use distributed transactions initiated by remote clients</li>
</ul>
</ul>
<ul>
<ul>
<li>Applications that are heavily message-oriented and need message-driven beans</li>
</ul>
</ul>
<p>On the other hand, Hibernate framework has reached a vast community of developers and it offers the benefit of peacefully coexisting in various deployment environments, from application servers to standalone applications.</p>
<p>At the end of the day, the choice between the two technologies might be to preserve your well-tested applications backed by Hibernate Persistence and to definitely consider switching to JPA when you are designing a new project from the ground up. What about using them together instead?</p>
<h2>Using Hibernate with EJB</h2>
<p>A plausible scenario is that some time ago, you designed the persistence layer of your application with Hibernate. Now you need to expose some functionalities of your application through RMI or Web Services.</p>
<p>The good news is that persistent classes that are mapped using Hibernate *.hbm. xml files are supported by JBoss AS EJB 3 implementation. The <b>EJB 3 deployer </b>will search the archive for any .hbm.xml files and add them to the definition of the underlying Hibernate SessionFactory. Let&#8217;s see how you can leverage Hibernate objects from the EJB environment.</p>
<h2>Injecting key Hibernate objects</h2>
<p>If you have been through the Hibernate web application carefully, you might advocate that it is not a pure MVC application, as we are accessing the persistence layer from within the servlet.</p>
<p>This approach can be useful for a learner who wants an easy-to-catch example of Hibernate. However, you can create a clean separation of roles between the controller and the model tier, also by introducing an EJB as intermediary.</p>
<p>From inside your Hibernate project, add another Stateless Session Bean named com.packtpub.hibernate.HibernateDAOBean implementing a local interface com.packtpub.hibernate.HibernateDAOLocal.</p>
<p>Following is a code snippet of the bean implementing the saveEmployee method:</p>
<pre class="brush: java; title: ; notranslate">	@Stateless
	@LocalBinding(jndiBinding=&quot;HibernateDAO/local&quot;)
	public class HibernateDAOBean implements HibernateDAO {
		&lt;b&gt;@PersistenceUnit(unitName=&quot;hibernateUnit&quot;) [1]
			SessionFactory factory;&lt;/b&gt;
		public void saveEmployee(String name,String salary,String
			departmentId) {
			Session hsession=null;
			try {
				hsession = factory.openSession();
				Query query = hsession.createQuery(&quot;from Department d where
				d.departmentId = :departmentId&quot;);
				query.setInteger(&quot;departmentId&quot;, new Integer(departmentId));
				Department dep = (Department) query.uniqueResult();
				Employee emp = new Employee();
				emp.setDepartment(dep);
				emp.setEmployeeName(name);
				emp.setEmployeeSalary(Integer.parseInt(salary));
				hsession.save(emp);
			}
			catch (Exception e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
				throw new EJBException(e.getMessage());
			}
			finally {
				if (hsession.isOpen())
				hsession.close();
			}
		}</pre>
<p>The most interesting point in this example is that you have injected the Hibernate SessionFactory in your bean by means of the persistence unit named hibernateUnit. Therefore, you have to equip your application with a JPA persistence.xml file:</p>
<pre class="brush: java; title: ; notranslate">	&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
		&lt;persistence version=&quot;1.0&quot; xmlns=&quot;http://java.sun.com/xml/ns/
			persistence&quot; xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
			xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/persistence http://
			java.sun.com/xml/ns/persistence/persistence_1_0.xsd&quot;&gt;
			&lt;b&gt;&lt;persistence-unit name=&quot;hibernateUnit&quot; transaction-type=&quot;JTA&quot;&gt;&lt;/b&gt;
				&lt;provider&gt;org.hibernate.ejb.HibernatePersistence&lt;/provider&gt;
				&lt;jta-data-source&gt;java:/MySqlDS&lt;/jta-data-source&gt;
				&lt;properties&gt;
					&lt;property name=&quot;hibernate.dialect&quot;
						value=&quot;org.hibernate.dialect.MySQLDialect&quot;/&gt;
				&lt;/properties&gt;
			&lt;/persistence-unit&gt;
		&lt;/persistence&gt;</pre>
<p>We leave as exercise to the reader to complete the EJB with all other methods. On the web tier, you will do a clear cut of all the persistence stuff, just taking care to invoke the EJB with the parameters collected from the request. Look how simple and effective your servlet method saveEmployee has become:</p>
<pre class="brush: java; title: ; notranslate">	&lt;b&gt;@EJB(mappedName = &quot;HibernateDAO/local&quot;)
	HibernateDAO hibernateDAO;&lt;/b&gt;
		private String saveEmployee(HttpServletRequest request) {
			Session hsession=null;
			String name=request.getParameter(&quot;name&quot;);
			String salary=request.getParameter(&quot;salary&quot;);
			String departmentId=request.getParameter(&quot;departmentId&quot;);
			try {
				hibernateDAO.saveEmployee(name,salary,departmentId);
			}
			catch (Exception e) {
				e.printStackTrace();
			}
			return employeeList(request);
		}</pre>
<p>A snapshot of the complete Hibernate EJB-driven project follows here:</p>
<p><center><a href="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-20.jpg"><img class="aligncenter size-full wp-image-6650" alt="jboss-hibernate-20" src="http://www.javabeat.net/wp-content/uploads/2010/02/jboss-hibernate-20.jpg" width="401" height="524" /></a></center> As you can see, using Hibernate API works much the same way as the EntityManager interface. This example reveals another difference with our former web application. Here the EJB must not attempt to manage the life cycle of the Hibernate session; this is done internally by the EJB container, which is in charge of committing or rolling back the transaction, following the EJB container&#8217;s policies.</p>
<h2>Summary</h2>
<p>Hibernate is a fl exible framework that can be used in any Java application environment. In our excursus, we have showed how to develop a sample application that is geared toward a managed environment. In the last two sections of the chapter, we have compared the Hibernate framework with the JPA persistence standard, showing how the two technologies can be coupled in a single application.</p>
<p>In the next chapter, we will learn JBoss AS JMX infrastructure, which was the backbone of earlier releases of JBoss. Even if it&#8217;s not the main kernel component anymore, the JMX API is still the glue around many JBoss AS services.</p>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fweb-servers%2Fjboss-web-servers%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/web-servers/jboss-web-servers/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/web-servers/jboss-web-servers/feed/" data-count="vertical" data-text="JBoss" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/02/developing-applications-with-jboss-and-hibernate/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JBoss Portal Server Development</title>
		<link>http://www.javabeat.net/2009/02/jboss-portal-server-development/</link>
		<comments>http://www.javabeat.net/2009/02/jboss-portal-server-development/#comments</comments>
		<pubDate>Tue, 17 Feb 2009 15:58:43 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JBoss]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=2237</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Enterprises need more than just basic services; they need value-creating entities, which are crucial for running a successful business. Portals offer tremendous value to enterprises, and JBoss Portal Server is a popular, feature-rich open-source server that provides a standards-compliant platform for hosting functionality that serves the diverse portal needs of an enterprise. Its primary strength [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p>Enterprises need more than just basic services; they need value-creating entities, which are crucial for running a successful business. Portals offer tremendous value to enterprises, and JBoss Portal Server is a popular, feature-rich open-source server that provides a standards-compliant platform for hosting functionality that serves the diverse portal needs of an enterprise. Its primary strength lies in its ability to provide robust support for custom implementation of functionality using the JSR-168 portlet API.</p>
<p>This book is a practical guide to installing, configuring, and using JBoss Portal Server. It explains, with examples, how to easily build feature-rich portals using JBoss. As you move further on, you will learn to personalize your portals and add new features to them.<br />
This book will equip you with everything you need to know about JBoss Portal Server to build a fully-functional portal. It will help you to quickly understand and build enterprise portals with rich features, such as personalization, AJAX, single sign-on, Google widget integration, remote portlet integration, content management, and more. Along with feature implementation, the book will also provide developers with enough detail to be able to tune and customize the portal environment to best suit the platform needs.</p>
<h2>What This Book Covers</h2>
<p><i>Chapter 1</i> reviews portals, their functions, and their values. It talks about portal servers and the specifications that govern the creation and management of portals on the J2EE platform. Portal servers go beyond serving custom content and provide a feature-rich set of robust pre-built functions that take away the need to create certain fundamental sets of features from scratch each time. This chapter shows that, by removing the development efforts behind creating such features, portal developers can now spend their time and money on developing business functions.</p>
<p><i>Chapter 2</i> talks in detail about the installation process of JBoss portal, with an emphasis on the differences and caveats for the various installation types offered, depending on the usage scenarios. A simplified installation and deployment process facilitates faster implementation and fewer problems, as demonstrated by almost immediate creation and management of pages on the platform.</p>
<p><i>Chapter 3</i> goes a bit deeper into JBoss portal server and explains portlets better by creating a simple portlet application. It goes through the complete life cycle from code creation to deployment. This overview tour gives you a good idea of the major components that are required to create a functional portlet.</p>
<p><i>Chapter 4</i> reviews the various options that are available to effectively manage the presentation of portlets using technologies such as JSP, JSF, and so on. It shows a few examples of each one of them. To understand the concepts better, a portal application is created from scratch and a custom portlet, created with JSP-based view is added to this new application.</p>
<p><i>Chapter 5</i> reviews how the power of portals can be extended by facilitating features such as customization and personalization. It further extendeds our example portal to include custom layouts, themes, and other personalization features. It also shows how we can personalize a page and offer the users options for controlling the contents on the page.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p><i>Chapter 6</i> shows how JBoss portal blends the dynamism and rich functionality offered by AJAX with its strong portal architecture, to provide users with choices for developing highly-functional portal applications. It also discusses the limitations of the current specification and walks through an example that shows how easy it is to develop and deploy AJAX-based portlets.</p>
<p><i>Chapter 7</i> talks about how Hibernate, a very popular ORM tool, is used internally by JBoss applications, and how applications can integrate database support into portlet applications by using Hibernate.</p>
<p><i>Chapter 8</i> elaborates upon a simple but robust content management system provided by the JBoss portal that is sufficient for most of the needs for a portal application. Using interceptors, CMSAdmin, and CMS Portlets, the user can develop a functionality that helps to effectively manage and deliver content. This chapter extends our example further, to add some new content, and then edit it. It also shows how easy it is to add, edit, and manage content in the portal.</p>
<p><i>Chapter 9</i> discusses the various aspects of security as they relate to JBoss portal server and its functional components—the portal objects. JBoss portal allows a fine-grained level of control over portal objects such as portal instances, pages, and portlets. Security is an important function of an application. JBoss portal offers a varied set of options that allow the building of highly secure enterprise applications on the portal server.</p>
<p><i>Chapter 10</i> discusses the basics of remoting portlets before it goes into a few implementations using some real-world examples. It talks about how easily the portlets can be exposed as remotely available services, and how remote services can be consumed relatively effortlessly.</p>
<p><i>Chapter 11</i> talks about some of the features specified by the new portlet specification, such as portlet co-ordination, and filters introduction. It tells us how Portlet 2.0 provides a comprehensive set of options for performing robust portlet coordination by using events, as well as public parameters that tremendously increases the capabilities of portals and portlets by opening up possibilities for integrating not only within the application, but also with other applications within the enterprise.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/jboss-portal-server-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
