<?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>PlanetMysql.ru - информация о СУБД MySQL &#187; v3</title>
	<atom:link href="http://planetmysql.ru/category/v3/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Fri, 10 Feb 2012 20:01:53 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>TOTD #122: Creating a JPA Persistence Unit using NetBeans 6.8</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_122_creating_a_jpa?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-122-creating-a-jpa-persistence-unit-using-netbeans-6-8</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_122_creating_a_jpa#comments</comments>
		<pubDate>Wed, 10 Feb 2010 07:08:43 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[eclipselink]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[persistenceunit]]></category>
		<category><![CDATA[sakila]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_122_creating_a_jpa</guid>
		<description><![CDATA[Taking TOTD #121 forward, this blog explains how to create a JPA Persistence Unit for a MySQL sample database and package it as a library. This JAR file can then be easily included in other web applications.
Lets get started!

    Configure GlassFish for using the MySQL sample database (sakila) as described in TOTD #121.
    Add the GlassFish instance in NetBeans IDE using &#34;Services&#34; panel.
    
Create JPA entities using NetBeans IDE.
        
            Create a Java class library:Our ultimate goal is to create a reusable JAR file and that's why this project type is chosen.
            Specify the name of project as &#34;SakilaPU&#34;:
            Right-click on the project and select &#34;New&#34;, &#34;Entity Classes from Database ...&#34; to initiate the process of entity generation:
            
Choose the database connection as:If not configured, then can be easily done by clicking on &#34;New Database Connection ...&#34; in the list box.
                
                    Click on &#34;Add All &#62;&#62;&#34; to generate the mapped JPA entities for all tables and views.
                    The views do not have primary keys and will need to be appropriately annotated (described later).
                    Click on &#34;Next &#62;&#34;.
                
            
            Give the package name as:and specify the package name as &#34;sakila&#34;. Click on &#34;Create Persistence Unit ...&#34;.
            Change the default PU name from &#34;SakilaPUPU&#34; to &#34;SakilaPU&#34;:and click on &#34;Finish&#34;. Notice that &#34;EclipseLink&#34;, the Reference Implementation of JPA 2.0, is used as the persistence library.
            
Add &#34;@javax.persistence.Id&#34; annotation to the following class/field combination:
                
                    
                        Class
                        Field
                    
                    
                        sakila.SalesByFilmCategory
                        category
                    
                    
                        sakila.ActorInfo
                        actorId
                    
                    
                        sakila.FilmList
                        fid
                    
                    
                        sakila.CustomerList
                        id
                    
                    
                        sakila.NicerButSlowerFilmList
                        fid
                    
                    
                        sakila.StaffList
                        id
                    
                    
                        sakila.SalesByStore
                        store
                    
                
This is required because none of the &#34;views&#34; are defined with a primary key.            
            
                Right-click on the project and select &#34;Clean &#38; Build&#34;. This generates &#34;dist/SakilaPU.jar&#34; and the structure looks like:
                
            
        
    

This JAR file can now be included in any web application. The pre-built JAR file can also be downloaded here. The key items to note about this pre-built JAR:

    Persistence Unit Name: &#34;SakilaPU&#34;
    All classes are in &#34;sakila.*&#34; package.
    Each class has a pre-defined &#34;&#60;CLASS-NAME&#62;.findAll&#34; named query that returns all elements from the underlying view/table.
    Can be easily added in &#34;WEB-INF/lib&#34; directory of your web application.

Even though this blog uses a MySQL sample database, these steps can be easily followed for any other database such as Oracle or JavaDB.
Technorati: totd javaee glassfish v3 jpa eclipselink persistenceunit mysql sakila netbeans]]></description>
			<content:encoded><![CDATA[<p>Taking <a href="http://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for">TOTD #121</a> forward, this blog explains how to create a JPA Persistence Unit for a MySQL sample database and package it as a library. This JAR file can then be easily included in other web applications.</p>
<p>Lets get started!</p>
<ol>
    <li>Configure <a href="http://glassfish.org">GlassFish</a> for using the MySQL sample database (<a href="http://dev.mysql.com/doc/sakila/en/sakila.html">sakila</a>) as described in <a href="http://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for">TOTD #121</a>.</li>
    <li>Add the GlassFish instance in <a href="http://netbeans.org">NetBeans IDE</a> using &quot;Services&quot; panel.</li>
    <li>
Create JPA entities using NetBeans IDE.
        <ol>
            <li>Create a Java class library:<br /><br /><img border="1" style="margin: 5px" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-create-java-class-library.png" /><br /><br />Our ultimate goal is to create a reusable JAR file and that's why this project type is chosen.<br /></li>
            <li>Specify the name of project as &quot;SakilaPU&quot;:<br /><br /><img border="1" style="margin: 5px" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-name-and-location.png" /><br /></li>
            <li>Right-click on the project and select &quot;New&quot;, &quot;Entity Classes from Database ...&quot; to initiate the process of entity generation:<br /><br /><img border="1" style="margin: 5px" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-entity-classes-from-database.png" /></li>
            <li>
Choose the database connection as:<br /><br /><img border="1" style="margin: 5px" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-db-connection.png" /><br /><br />If not configured, then can be easily done by clicking on &quot;New Database Connection ...&quot; in the list box.
                <ol>
                    <li>Click on &quot;Add All &gt;&gt;&quot; to generate the mapped JPA entities for all tables and views.</li>
                    <li>The views do not have primary keys and will need to be appropriately annotated (described later).</li>
                    <li>Click on &quot;Next &gt;&quot;.<br /></li>
                </ol>
            </li>
            <li>Give the package name as:<br /><br /><img border="1" style="margin: 5px" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-package-name.png" /><br /><br />and specify the package name as &quot;sakila&quot;. Click on &quot;Create Persistence Unit ...&quot;.</li>
            <li>Change the default PU name from &quot;SakilaPUPU&quot; to &quot;SakilaPU&quot;:<br /><br /><img border="1" style="margin: 5px" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-create-pu.png" /><br /><br />and click on &quot;Finish&quot;. Notice that &quot;EclipseLink&quot;, the Reference Implementation of JPA 2.0, is used as the persistence library.</li>
            <li>
Add &quot;@javax.persistence.Id&quot; annotation to the following class/field combination:
                <table border="0" width="60%">
                    <tr>
                        <th>Class</th>
                        <th>Field</th>
                    </tr>
                    <tr>
                        <td>sakila.SalesByFilmCategory</td>
                        <td>category</td>
                    </tr>
                    <tr>
                        <td>sakila.ActorInfo</td>
                        <td>actorId</td>
                    </tr>
                    <tr>
                        <td>sakila.FilmList</td>
                        <td>fid</td>
                    </tr>
                    <tr>
                        <td>sakila.CustomerList</td>
                        <td>id</td>
                    </tr>
                    <tr>
                        <td>sakila.NicerButSlowerFilmList</td>
                        <td>fid</td>
                    </tr>
                    <tr>
                        <td>sakila.StaffList</td>
                        <td>id</td>
                    </tr>
                    <tr>
                        <td>sakila.SalesByStore</td>
                        <td>store</td>
                    </tr>
                </table>
<br />This is required because none of the &quot;views&quot; are defined with a primary key.            </li>
            <li>
                <p>Right-click on the project and select &quot;Clean &amp; Build&quot;. This generates &quot;dist/SakilaPU.jar&quot; and the structure looks like:</p>
                <p><img height="530" border="1" style="margin: 5px" width="296" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/02/totd122-jar-structure.png" /></p>
            </li>
        </ol>
    </li>
</ol>
<p><br /><br />This JAR file can now be included in any web application. The pre-built JAR file can also be <a href="http://blogs.sun.com/arungupta/resource/SakilaPU.jar">downloaded here</a>. The key items to note about this pre-built JAR:</p>
<ul>
    <li>Persistence Unit Name: &quot;SakilaPU&quot;</li>
    <li>All classes are in &quot;sakila.*&quot; package.</li>
    <li>Each class has a pre-defined &quot;&lt;CLASS-NAME&gt;.findAll&quot; named query that returns all elements from the underlying view/table.</li>
    <li>Can be easily added in &quot;WEB-INF/lib&quot; directory of your web application.</li>
</ul>
<p>Even though this blog uses a MySQL sample database, these steps can be easily followed for any other database such as Oracle or JavaDB.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd</a> <a href="http://technorati.com/tags/javaee">javaee</a> <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/jpa">jpa</a> <a href="http://technorati.com/tags/eclipselink">eclipselink</a> <a href="http://technorati.com/tags/persistenceunit">persistenceunit</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/sakila">sakila</a> <a href="http://technorati.com/tags/netbeans">netbeans</a></small></p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23404&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23404&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/02/10/totd-122-creating-a-jpa-persistence-unit-using-netbeans-6-8/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #121: JDBC resource for MySQL and Oracle sample database in GlassFish v3</title>
		<link>http://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-121-jdbc-resource-for-mysql-and-oracle-sample-database-in-glassfish-v3</link>
		<comments>http://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for#comments</comments>
		<pubDate>Tue, 09 Feb 2010 07:00:17 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[oracle]]></category>
		<category><![CDATA[sakila]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for</guid>
		<description><![CDATA[This blog clearly explains how to configure the MySQL sample database (sakila) with GlassFish. Even though the instructions use a specific database but should work for other databases (such as Oracle, JavaDB, PostgreSQL, and others) as well. The second half of the blog provide specific syntax for the Oracle sample database.

    Download sakila sample database and unzip the archive.
    Install the database as described here - basically load and run &#34;sakila-schema.sql&#34; and &#34;sakila-data.sql&#34; extracted from the archive.
    
Create a new MySQL user account using MySQL CLI Admin and assign the privileges
        
            
Using &#34;root&#34; user (sudo mysql --user root)
                
CREATE USER glassfish IDENTIFIED BY 'glassfish';
GRANT ALL PRIVILEGES ON *.* TO 'glassfish'@'localhost' IDENTIFIED BY 'glassfish';
FLUSH PRIVILEGES;

            
            
Using &#34;glassfish&#34; user (sudo mysql --user glassfish)
                
source sakila-schema.sql;
source sakila-data.sql;

            
        
    
    Download Connector/J, unzip and copy &#34;mysql-connector-java-5.x.x-bin.jar&#34; to &#34;glassfish/domains/domain1/lib/ext&#34; directory.
    
Start GlassFish server as:
        
asadmin start-domain


    
    
Create a JDBC resource
        
            
Create JDBC connection pool as:
                
asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype javax.sql.DataSource --property "User=glassfish:Password=glassfish:URL=jdbc\:mysql\://localhost/sakila" jdbc/sakilaPool

            
            
Test the JDBC connection pool as:
                
asadmin ping-connection-pool jdbc/sakilaPool

            
            
Create the JDBC resource as:
                
asadmin create-jdbc-resource --connectionpoolid jdbc/sakilaPool jdbc/sakila

            
        
    

That's it!
Creating a JDBC resource for any other database requires the following updates to the steps mentioned above. Lets consider modifying these steps for the Oracle sample database.

    
Use the client interface SQL*PLus and connect as:         
sqlplus "/ as sysdba"

create user and grant the privileges as:
        
CREATE USER glassfish IDENTIFIED BY glassfish DEFAULT tablespace users TEMPORARY tablespace temp;
GRANT CONNECT TO glassfish IDENTIFIED BY glassfish;
GRANT UNLIMITED TABLESPACE TO glassfish;
GRANT CREATE TABLE TO glassfish;
GRANT CREATE SEQUENCE TO glassfish;

    
    Copy the appropriate JDBC driver (ojdbc6.jar).
    
Create the JDBC resource as:
        
asadmin create-jdbc-connection-pool --datasourceclassname oracle.jdbc.pool.OracleDataSource --restype javax.sql.DataSource --property "User=hr:Password=hr:URL=jdbc\:oracle\:thin\:@localhost\:1521\:orcl" jdbc/hr
asadmin ping-connection-pool jdbc/hr
asadmin create-jdbc-resource --connectionpoolid jdbc/hr jdbc/hr

as explained in TOTD #108.    

Here are a few other related entries:

    
        RESTful representation of sakila using NetBeans and GlassFish
    
    
        JPA + Servlet 3.0 Application using Sakila in Eclipse
    
    
        JSF + JPA + EJB Application using Oracle, NetBeans, and GlassFish
    

Technorati: totd javaee glassfish v3 jpa mysql sakila oracle]]></description>
			<content:encoded><![CDATA[<p>This blog clearly explains how to configure the MySQL sample database (<a href="http://dev.mysql.com/doc/sakila/en/sakila.html">sakila</a>) with <a href="http://glassfish.org">GlassFish</a>. Even though the instructions use a specific database but should work for other databases (such as Oracle, JavaDB, PostgreSQL, and others) as well. The second half of the blog provide specific syntax for the Oracle sample database.</p>
<ol>
    <li>Download <a href="http://downloads.mysql.com/docs/sakila-db.zip">sakila sample database</a> and unzip the archive.</li>
    <li>Install the database as described <a href="http://dev.mysql.com/doc/sakila/en/sakila.html#sakila-installation">here</a> - basically load and run &quot;sakila-schema.sql&quot; and &quot;sakila-data.sql&quot; extracted from the archive.</li>
    <li>
Create a new MySQL user account using MySQL CLI Admin and assign the privileges
        <ol>
            <li>
Using &quot;root&quot; user (sudo mysql --user root)<br />
                <pre>
CREATE USER glassfish IDENTIFIED BY 'glassfish';
GRANT ALL PRIVILEGES ON *.* TO 'glassfish'@'localhost' IDENTIFIED BY 'glassfish';
FLUSH PRIVILEGES;
</pre>
            </li>
            <li>
Using &quot;glassfish&quot; user (sudo mysql --user glassfish)
                <pre>
source sakila-schema.sql;
source sakila-data.sql;
</pre>
            </li>
        </ol>
    </li>
    <li>Download <a href="http://dev.mysql.com/downloads/connector/j/">Connector/J</a>, unzip and copy &quot;mysql-connector-java-5.x.x-bin.jar&quot; to &quot;glassfish/domains/domain1/lib/ext&quot; directory.</li>
    <li>
Start GlassFish server as:
        <pre>
asadmin start-domain

</pre>
    </li>
    <li>
Create a JDBC resource
        <ol>
            <li>
Create JDBC connection pool as:
                <pre>
asadmin create-jdbc-connection-pool --datasourceclassname com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype javax.sql.DataSource --property "User=glassfish:Password=glassfish:URL=jdbc\:mysql\://localhost/sakila" jdbc/sakilaPool
</pre>
            </li>
            <li>
Test the JDBC connection pool as:
                <pre>
asadmin ping-connection-pool jdbc/sakilaPool
</pre>
            </li>
            <li>
Create the JDBC resource as:
                <pre>
asadmin create-jdbc-resource --connectionpoolid jdbc/sakilaPool jdbc/sakila
</pre>
            </li>
        </ol>
    </li>
</ol>
<p>That's it!</p>
<p>Creating a JDBC resource for any other database requires the following updates to the steps mentioned above. Lets consider modifying these steps for the Oracle sample database.</p>
<ol>
    <li>
Use the client interface SQL*PLus and connect as:<br />         <pre>
sqlplus "/ as sysdba"
</pre>
<br />create user and grant the privileges as:<br />
        <pre>
CREATE USER glassfish IDENTIFIED BY glassfish DEFAULT tablespace users TEMPORARY tablespace temp;
GRANT CONNECT TO glassfish IDENTIFIED BY glassfish;
GRANT UNLIMITED TABLESPACE TO glassfish;
GRANT CREATE TABLE TO glassfish;
GRANT CREATE SEQUENCE TO glassfish;
</pre>
    </li>
    <li>Copy the appropriate JDBC driver (<a href="http://download.oracle.com/otn/utilities_drivers/jdbc/112/ojdbc6.jar">ojdbc6.jar</a>).</li>
    <li>
Create the JDBC resource as:<br />
        <pre>
asadmin create-jdbc-connection-pool --datasourceclassname oracle.jdbc.pool.OracleDataSource --restype javax.sql.DataSource --property "User=hr:Password=hr:URL=jdbc\:oracle\:thin\:@localhost\:1521\:orcl" jdbc/hr
asadmin ping-connection-pool jdbc/hr
asadmin create-jdbc-resource --connectionpoolid jdbc/hr jdbc/hr
</pre>
<br />as explained in <a href="http://blogs.sun.com/arungupta/entry/totd_108_java_ee_6">TOTD #108</a>.    </li>
</ol>
<p>Here are a few other related entries:</p>
<ul>
    <li>
        <p><a href="http://blogs.sun.com/arungupta/entry/restful_representation_of_sakila_using">RESTful representation of sakila using NetBeans and GlassFish</a></p>
    </li>
    <li>
        <p><a href="http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java">JPA + Servlet 3.0 Application using Sakila in Eclipse</a></p>
    </li>
    <li>
        <p><a href="http://blogs.sun.com/arungupta/entry/totd_108_java_ee_6">JSF + JPA + EJB Application using Oracle, NetBeans, and GlassFish</a></p>
    </li>
</ul>
<p><small>Technorati: <a href="http://technorati.com/tags/totd">totd</a> <a href="http://technorati.com/tags/javaee">javaee</a> <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/jpa">jpa</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/sakila">sakila</a> <a href="http://technorati.com/tags/oracle">oracle</a></small></p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23392&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23392&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/02/09/totd-121-jdbc-resource-for-mysql-and-oracle-sample-database-in-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #109: How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_109_how_to_convert?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_109_how_to_convert#comments</comments>
		<pubDate>Fri, 02 Oct 2009 22:40:00 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee6]]></category>
		<category><![CDATA[javaserverfaces]]></category>
		<category><![CDATA[jsr299]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[v3]]></category>
		<category><![CDATA[webbeans]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_109_how_to_convert</guid>
		<description><![CDATA[Content available at http://blog.arungupta.me/2009/10/totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans/.]]></description>
			<content:encoded><![CDATA[Content available at <a href="http://blog.arungupta.me/2009/10/totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans/" />http://blog.arungupta.me/2009/10/totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans/</>.<br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=21429&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=21429&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2009/10/03/totd-109-how-to-convert-a-jsf-managed-bean-to-jsr-299-bean-web-beans/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #95: EJB 3.1 + Java Server Faces 2.0 + JPA 2.0 web application &#8212; Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1#comments</comments>
		<pubDate>Mon, 17 Aug 2009 10:00:00 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[ejb]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee6]]></category>
		<category><![CDATA[javaserverfaces]]></category>
		<category><![CDATA[jpa2]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1</guid>
		<description><![CDATA[
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. TOTD
#94 built upon it by using Java Server Faces 2 instead of
Servlet 3.0 for displaying the results. However we are still using a
POJO
for all the database interactions. This works fine if we are only
reading values from the database but that's not how a typical web
application behaves. The web application would typically perform all
CRUD operations. More typically they like to perform one or more CRUD
operations within the context of a transaction. And how do you do
transactions in the context of a web application ? Java EE 6 comes to
your rescue.

The EJB 3.1
specification (another new specification in Java EE 6) allow
POJO classes to be annotated with @EJB and bundled within
WEB-INF/classes of a WAR file. And so you get all transactional
capabilities in your web application very easily.

This&#160;Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #94 and use EJB 3.1 instead
of the JSF managed bean
for
performing the business logic. There are two ways to achieve this
pattern as described below.

Lets call this TOTD #95.1

  The easiest way to back a JSF page with an EJB is to
convert the managed bean into an EJB by adding @javax.ejb.Stateless
annotation. So change the&#160; "StateList" class from TOTD #94 as
shown below:
    
    
      
        
          @javax.ejb.Stateless
@ManagedBean
public class StateList {
&#160;&#160;&#160; @PersistenceUnit
&#160;&#160;&#160; EntityManagerFactory emf;
          
&#160;&#160;&#160; public List&#60;States&#62;
getStates() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;
return
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();
&#160;&#160;&#160; }
}
        
      
    
    
The change is highlighted in bold, and that's it!

Because of "Deploy-on-save" feature in NetBeans and GlassFish v3, the
application is autodeployed. Otherwise right-click on the project and
select Run (default shortcut "F6"). As earlier, the results can be seen
at "http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp" or
"http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml"
and looks like:



The big difference this time is that the business logic is executed by
an EJB in a fully transactional manner. Even though the logic in this
case is a single read-only operation to the database, but you get the
idea :)

Alternatively, you can use the delegate pattern in the managed bean as
described below. Lets call this #95.2.

  Right-click on the project, select "New", "Session Bean
..." and create a stateless session bean by selecting the options as
shown below:
    
    
    
This creates a stateless session with the name "StateBeanBean" (bug
#170392 for redundant "Bean" in the name).
  Simplify your managed bean by refactoring all the business
logic to the EJB as shown below:
    
    
      
        
          @Stateless
public class StateBeanBean {
&#160;&#160;&#160; @PersistenceUnit
&#160;&#160;&#160; EntityManagerFactory emf;
&#160;&#160; &#160;
&#160;&#160;&#160; public List&#60;States&#62;
getStates() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;
return
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();
&#160;&#160;&#160; }
}
        
      
    
    
and 
    
    
      
        
          @ManagedBean
public class StateList {
&#160;&#160;&#160; @EJB StateBeanBean bean;
          
&#160;&#160;&#160; public List&#60;States&#62;
getStates() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;
return bean.getStates();
&#160;&#160;&#160; }
}
          
        
      
    
    
In fact the EJB code can be further simplified to:
    
    
      
        
          @Stateless
public class StateBeanBean {
&#160;&#160;&#160; @PersistenceContext
          &#160;&#160;&#160;
EntityManager em;
&#160;&#160;&#160; 
&#160;&#160;&#160; public List&#60;States&#62;
getStates() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;
return em.createNamedQuery("States.findAll").getResultList();
&#160;&#160;&#160; }
}
          
        
      
    
    
The changes are highlighted in bold.
  

If the application is already running then Deploy-on-Save
would have automatically deployed the entire application. Otherwise
right-click on the project and select Run (default shortcut "F6").
Again, the
results can be seen at
"http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp" or
"http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml"
and are displayed as shown in the screenshot above.

The updated directory structure looks like:



The important point to note is that our EJB is bundled in the WAR file
and no additional deployment descriptors were added or existing ones
modified to achieve that. Now, that's really clean :)

The next blog in this series will show how managed beans can be
replaced with WebBeans, err JCDI.

Also refer to other Java EE 6
blog entries. 

Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available here.


Technorati: totd
glassfish
v3 mysql javaee6 javaserverfaces
jpa2 ejb netbeans
]]></description>
			<content:encoded><![CDATA[<br>
<a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD
#93</a>
showed how to get started with <a href="http://jcp.org/en/jsr/detail?id=316">Java EE 6</a>
using <a href="http://www.netbeans.org/servlets/NewsItemView?newsItemID=1413">NetBeans
6.8 M1</a> and
<a href="http://glassfish.org">GlassFish v3</a> by
building a simple Servlet 3.0 + JPA 2.0 web
application. <a href="http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java">TOTD
#94</a> built upon it by using Java Server Faces 2 instead of
Servlet 3.0 for displaying the results. However we are still using a
POJO
for all the database interactions. This works fine if we are only
reading values from the database but that's not how a typical web
application behaves. The web application would typically perform all
CRUD operations. More typically they like to perform one or more CRUD
operations within the context of a transaction. And how do you do
transactions in the context of a web application ? Java EE 6 comes to
your rescue.<br>
<br>
The <a href="http://jcp.org/en/jsr/detail?id=318">EJB 3.1
specification</a> (another new specification in Java EE 6) allow
POJO classes to be annotated with @EJB and bundled within
WEB-INF/classes of a WAR file. And so you get all transactional
capabilities in your web application very easily.<br>
<br>
This&nbsp;<span>T</span>ip
<span>O</span>f <span>T</span>he <span>D</span>ay (TOTD) shows how
to enhance the application created in TOTD #94 and use EJB 3.1 instead
of the JSF <span>managed bean</span>
for
performing the business logic. There are two ways to achieve this
pattern as described below.<br>
<br>
Lets call this TOTD #95.1<br>
<ol>
  <li>The easiest way to back a JSF page with an EJB is to
convert the managed bean into an EJB by adding @javax.ejb.Stateless
annotation. So change the&nbsp; "StateList" class from TOTD #94 as
shown below:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td><span>@javax.ejb.Stateless</span><br>
@ManagedBean<br>
public class StateList {<br>
&nbsp;&nbsp;&nbsp; @PersistenceUnit<br>
&nbsp;&nbsp;&nbsp; EntityManagerFactory emf;<br>
          <br>
&nbsp;&nbsp;&nbsp; public List&lt;States&gt;
getStates() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();<br>
&nbsp;&nbsp;&nbsp; }<br>
}</td>
        </tr>
      </tbody>
    </table>
    <br>
The change is highlighted in bold, and that's it!</li>
</ol>
Because of "Deploy-on-save" feature in NetBeans and GlassFish v3, the
application is autodeployed. Otherwise right-click on the project and
select Run (default shortcut "F6"). As earlier, the results can be seen
at "http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp" or
"http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml"
and looks like:<br>
<br>
<img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-ejb-1st-output.png" /><br>
<br>
The big difference this time is that the business logic is executed by
an EJB in a fully transactional manner. Even though the logic in this
case is a single read-only operation to the database, but you get the
idea :)<br>
<br>
Alternatively, you can use the delegate pattern in the <span>managed bean</span> as
described below. Lets call this #95.2.
<ol>
  <li>Right-click on the project, select "New", "Session Bean
..." and create a stateless session bean by selecting the options as
shown below:<br>
    <br>
    <span><img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-ejb-create.png" /></span><br>
    <br>
This creates a stateless session with the name "StateBeanBean" (<a href="http://www.netbeans.org/issues/show_bug.cgi?id=170392">bug
#170392</a> for redundant "Bean" in the name).</li>
  <li>Simplify your managed bean by refactoring all the business
logic to the EJB as shown below:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>@Stateless<br>
public class StateBeanBean {<br>
&nbsp;&nbsp;&nbsp; @PersistenceUnit<br>
&nbsp;&nbsp;&nbsp; EntityManagerFactory emf;<br>
&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; public List&lt;States&gt;
getStates() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();<br>
&nbsp;&nbsp;&nbsp; }<br>
}</td>
        </tr>
      </tbody>
    </table>
    <br>
and <br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>@ManagedBean<br>
public class StateList {<br>
&nbsp;&nbsp;&nbsp; @EJB StateBeanBean bean;<br>
          <br>
&nbsp;&nbsp;&nbsp; public List&lt;States&gt;
getStates() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return bean.getStates();<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
          <span></span></td>
        </tr>
      </tbody>
    </table>
    <br>
In fact the EJB code can be further simplified to:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>@Stateless<br>
public class StateBeanBean {<br>
&nbsp;&nbsp;&nbsp; <span>@PersistenceContext</span><br>
          <span>&nbsp;&nbsp;&nbsp;
EntityManager em;</span><br>
&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp; public List&lt;States&gt;
getStates() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return <span>em.</span>createNamedQuery("States.findAll").getResultList();<br>
&nbsp;&nbsp;&nbsp; }<br>
}<br>
          <span></span></td>
        </tr>
      </tbody>
    </table>
    <br>
The changes are highlighted in bold.<br>
  </li>
</ol>
If the application is already running then <span>Deploy-on-Save</span>
would have automatically deployed the entire application. Otherwise
right-click on the project and select Run (default shortcut "F6").
Again, the
results can be seen at
"http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp" or
"http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml"
and are displayed as shown in the screenshot above.<br>
<br>
The updated directory structure looks like:<br>
<br>
<img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-ejb-dir-structure.png" /><br>
<br>
The important point to note is that our EJB is bundled in the WAR file
and no additional deployment descriptors were added or existing ones
modified to achieve that. Now, that's really clean :)<br>
<br>
The next blog in this series will show how managed beans can be
replaced with WebBeans, err JCDI.<br>
<br>
Also refer to other <a href="http://blogs.sun.com/arungupta/tags/javaee6">Java EE 6
blog entries</a>. <br>
<br>
Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available <a href="http://blogs.sun.com/arungupta/tags/totd">here</a>.
<br>
<br>
<small>Technorati: <a href="http://technorati.com/tags/totd">totd</a>
<a href="http://technorati.com/tags/glassfish">glassfish</a>
<a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/javaee6">javaee6</a> <a href="http://technorati.com/tags/javaserverfaces">javaserverfaces</a>
<a href="http://technorati.com/tags/jpa2">jpa2</a> <a href="http://technorati.com/tags/ejb">ejb</a> <a href="http://technorati.com/tags/netbeans">netbeans</a></small>
<br><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20667&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20667&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2009/08/17/totd-95-ejb-3-1-java-server-faces-2-0-jpa-2-0-web-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #94: A simple Java Server Faces 2.0 + JPA 2.0 application &#8212; Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java#comments</comments>
		<pubDate>Fri, 14 Aug 2009 10:00:00 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee6]]></category>
		<category><![CDATA[javaserverfaces]]></category>
		<category><![CDATA[jpa2]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java</guid>
		<description><![CDATA[
TOTD
#93
showed how to get started with Java EE 6
using NetBeans
6.8 M1 and
GlassFish v3 by
building a simple Servlet 3.0 + JPA 2.0 web
application. JPA 2.0 + Eclipselink was used for the database
connectivity
and Servlet 3.0 was used for displaying the results to the user. The
sample demonstrated how the two technologies can be mixed to create a
simple web application. But Servlets are meant for server-side
processing rather than displaying the results to end user. JavaServer
Faces 2 (another new specification in Java EE 6) is designed
to fulfill
that purpose.

This&#160;Tip
Of The Day (TOTD) shows how
to enhance the application created in TOTD #93 and use JSF 2 for
displaying the results.

  Right-click on the project, select "Properties", select
"Frameworks", click on "Add ..." as shown below:
    
    
    
Select "JavaServer Faces" and click on "OK". The following
configuration screen is shown:
    
    
    
Click on "OK" to complete the dialog. This generates a whole bunch of
files (7 to be accurate) in your project. Most of these files are
leftover from previous version of NetBeans and will be cleaned up. For
example, "faces-config.xml" is now optional and "forwardToJSF.jsp" is
redundant.
  Anyway, lets add a POJO class that will be our managed bean.
Right-click on "server" package and select "New", "Java Class ...",
give the name as "StateList". Change the class such that it looks like:
    
    
      
        
          package server;
          
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import states.States;
          
/**
&#160;* @author arungupta
&#160;*/
@ManagedBean
public class StateList {
&#160;&#160;&#160; @PersistenceUnit
&#160;&#160;&#160; EntityManagerFactory emf;
          
&#160;&#160;&#160; public List&#60;States&#62;
getStates() {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;
return
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();
&#160;&#160;&#160; }
}
        
      
    
    
Here are the main characterisitcs of this class:
  
  
    This is a POJO class with @ManagedBean annotation. This
annotation makes this class a managed
bean that can be used in the JSF pages. As no other
annotations or parameters are specified, this is a request-scoped
managed bean with the name "stateList" and lazily initialized. More
details about this annotation are available in the javadocs.
    The persistence unit created in TOTD
#93 is injected using @PersistenceUnit annotation.
    The POJO has one getter method that queries the database
and return the list of all the states.
    
  
  In the generated file "template-client.xhtml", change the
"head" template to:
    
    
      
        
          Show States
          
        
      
    
    
and "body" template to:
    
    
      
        
          &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#60;h:dataTable var="state" value="#{stateList.states}"
border="1"&#62;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#60;h:column&#62;&#60;h:outputText
value="#{state.abbrev}"/&#62;&#60;/h:column&#62;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#60;h:column&#62;&#60;h:outputText
value="#{state.name}"/&#62;&#60;/h:column&#62;
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
&#60;/h:dataTable&#62;
          
        
      
    
  
  
This uses the standard JSF "dataTable", "column", and "outputText" tags
and uses the value
expression to fetch the values from the managed bean.
  

If the application is already running from&#160;TOTD
#93, then Deploy-on-Save
would have automatically deployed the entire application. Otherwise
right-click on the project and select Run (default shortcut "F6"). The
results can be seen at
"http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp" or
"http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml"
and looks like:



The updated directory structure looks like:



There were multiple files added by the JSF framework support in
NetBeans. But as I said earlier, they will be cleaned up before the
final release.

Also refer to other Java EE 6
blog entries. 

Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available here.


Technorati: totd
glassfish
v3 mysql javaee6 javaserverfaces
jpa2 netbeans

]]></description>
			<content:encoded><![CDATA[<br>
<a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD
#93</a>
showed how to get started with <a href="http://jcp.org/en/jsr/detail?id=316">Java EE 6</a>
using <a href="http://www.netbeans.org/servlets/NewsItemView?newsItemID=1413">NetBeans
6.8 M1</a> and
<a href="http://glassfish.org">GlassFish v3</a> by
building a simple Servlet 3.0 + JPA 2.0 web
application. JPA 2.0 + Eclipselink was used for the database
connectivity
and Servlet 3.0 was used for displaying the results to the user. The
sample demonstrated how the two technologies can be mixed to create a
simple web application. But Servlets are meant for server-side
processing rather than displaying the results to end user. <a href="http://jcp.org/en/jsr/detail?id=314">JavaServer
Faces 2</a> (another new specification in Java EE 6) is designed
to fulfill
that purpose.<br>
<br>
This&nbsp;<span>T</span>ip
<span>O</span>f <span>T</span>he <span>D</span>ay (TOTD) shows how
to enhance the application created in TOTD #93 and use JSF 2 for
displaying the results.<br>
<ol>
  <li>Right-click on the project, select "Properties", select
"Frameworks", click on "Add ..." as shown below:<br>
    <br>
    <a href="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-jsf2-add-framework.png"><img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-jsf2-add-framework.png" /></a><br>
    <br>
Select "JavaServer Faces" and click on "OK". The following
configuration screen is shown:<br>
    <br>
    <a href="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-jsf2-framework-added.png"><img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-jsf2-framework-added.png" /></a><br>
    <br>
Click on "OK" to complete the dialog. This generates a whole bunch of
files (7 to be accurate) in your project. Most of these files are
leftover from previous version of NetBeans and will be cleaned up. For
example, "faces-config.xml" is now optional and "forwardToJSF.jsp" is
redundant.</li>
  <li>Anyway, lets add a POJO class that will be our <span>managed bean</span>.
Right-click on "server" package and select "New", "Java Class ...",
give the name as "StateList". Change the class such that it looks like:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>package server;<br>
          <br>
import java.util.List;<br>
import javax.faces.bean.ManagedBean;<br>
import javax.persistence.EntityManagerFactory;<br>
import javax.persistence.PersistenceUnit;<br>
import states.States;<br>
          <br>
/**<br>
&nbsp;* @author arungupta<br>
&nbsp;*/<br>
@ManagedBean<br>
public class StateList {<br>
&nbsp;&nbsp;&nbsp; @PersistenceUnit<br>
&nbsp;&nbsp;&nbsp; EntityManagerFactory emf;<br>
          <br>
&nbsp;&nbsp;&nbsp; public List&lt;States&gt;
getStates() {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
return
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();<br>
&nbsp;&nbsp;&nbsp; }<br>
}</td>
        </tr>
      </tbody>
    </table>
    <br>
Here are the main characterisitcs of this class:<br>
  </li>
  <ol>
    <li>This is a POJO class with @ManagedBean annotation. This
annotation makes this class a <span>managed
bean</span> that can be used in the JSF pages. As no other
annotations or parameters are specified, this is a request-scoped
managed bean with the name "stateList" and lazily initialized. More
details about this annotation are available in the <a href="https://javaserverfaces.dev.java.net/nonav/docs/2.0/managed-bean-javadocs/index.html">javadocs</a>.</li>
    <li>The persistence unit created in <a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD
#93</a> is injected using @PersistenceUnit annotation.</li>
    <li>The POJO has one getter method that queries the database
and return the list of all the states.<br>
    </li>
  </ol>
  <li>In the generated file "template-client.xhtml", change the
"head" template to:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>Show States<br>
          <span></span></td>
        </tr>
      </tbody>
    </table>
    <br>
and "body" template to:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;h:dataTable var="state" value="#{stateList.states}"
border="1"&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;h:column&gt;&lt;h:outputText
value="#{state.abbrev}"/&gt;&lt;/h:column&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;h:column&gt;&lt;h:outputText
value="#{state.name}"/&gt;&lt;/h:column&gt;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&lt;/h:dataTable&gt;<br>
          <span></span></td>
        </tr>
      </tbody>
    </table>
  </li>
  <br>
This uses the standard JSF "dataTable", "column", and "outputText" tags
and uses the <span>value
expression</span> to fetch the values from the <span>managed bean</span>.<br>
  <br>
</ol>
If the application is already running from&nbsp;<a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">TOTD
#93</a>, then <span>Deploy-on-Save</span>
would have automatically deployed the entire application. Otherwise
right-click on the project and select Run (default shortcut "F6"). The
results can be seen at
"http://localhost:8080/HelloEclipseLink/forwardToJSF.jsp" or
"http://localhost:8080/HelloEclipseLink/faces/template-client.xhtml"
and looks like:<br>
<br>
<img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-jsf2-output.png" /><br>
<br>
The updated directory structure looks like:<br>
<br>
<img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jee6-jsf2-dir-structure.png" /><br>
<br>
There were multiple files added by the JSF framework support in
NetBeans. But as I said earlier, they will be cleaned up before the
final release.<br>
<br>
Also refer to other <a href="http://blogs.sun.com/arungupta/tags/javaee6">Java EE 6
blog entries</a>. <br>
<br>
Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available <a href="http://blogs.sun.com/arungupta/tags/totd">here</a>.
<br>
<br>
<small>Technorati: <a href="http://technorati.com/tags/totd">totd</a>
<a href="http://technorati.com/tags/glassfish">glassfish</a>
<a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/javaee6">javaee6</a> <a href="http://technorati.com/tags/javaserverfaces">javaserverfaces</a>
<a href="http://technorati.com/tags/jpa2">jpa2</a> <a href="http://technorati.com/tags/netbeans">netbeans</a></small>
<br>
<br><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20638&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20638&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2009/08/14/totd-94-a-simple-java-server-faces-2-0-jpa-2-0-application-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>TOTD #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3 &#8212; A simple Servlet 3.0 + JPA 2.0 app</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-93-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3-a-simple-servlet-3-0-jpa-2-0-app</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with#comments</comments>
		<pubDate>Thu, 13 Aug 2009 10:00:00 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[javaee6]]></category>
		<category><![CDATA[jpa2]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[servlet3]]></category>
		<category><![CDATA[totd]]></category>
		<category><![CDATA[v3]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with</guid>
		<description><![CDATA[
NetBeans
6.8 M1 introduces support for creating Java EE 6 applications
... cool!

This Tip Of The Day (TOTD) shows how
to create a simple web application using JPA 2.0 and Servlet 3.0 and
deploy on GlassFish v3 latest
promoted build (58
as of this writing). If you can work with the one week older build then
NetBeans 6.8 M1 comes pre-bundled with 57. The example below should
work fine on that as well.

  Create the database, table, and populate some data into it
as shown below:
    
    
      
        
          ~/tools/glassfish/v3/58/glassfishv3/bin&#160;&#62;sudo mysql --user root
Password:
Welcome to the MySQL monitor.&#160; Commands end with ; or \g.
Your MySQL connection id is 1592
Server version: 5.1.30 MySQL Community Server (GPL)
          
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
          
mysql&#62; create
database states;
Query OK, 1 row affected (0.02 sec)
          
mysql&#62; CREATE
USER duke IDENTIFIED by 'glassfish';
Query OK, 0 rows affected (0.00 sec)
          
mysql&#62; GRANT ALL
on states.* TO duke;
Query OK, 0 rows affected (0.24 sec)
          
mysql&#62; use states;
          Database changed
          
mysql&#62; CREATE
TABLE STATES (
          &#160;&#160;&#160;
-&#62;&#160;&#160;&#160;&#160;&#160;&#160;
id INT,
          &#160;&#160;&#160;
-&#62;&#160;&#160;&#160;&#160;&#160;&#160;
abbrev VARCHAR(2),
          &#160;&#160;&#160;
-&#62;&#160;&#160;&#160;&#160;&#160;&#160;
name VARCHAR(50),
          &#160;&#160;&#160;
-&#62;&#160;&#160;&#160;&#160;&#160;&#160;
PRIMARY KEY (id)
          &#160;&#160;&#160;
-&#62; );
Query OK, 0 rows affected (0.16 sec)
          
mysql&#62; INSERT
INTO STATES VALUES (1, "AL", "Alabama");
          INSERT INTO
STATES VALUES (2, "AK", "Alaska");
          
. . .
          
mysql&#62; INSERT
INTO STATES VALUES (49, "WI", "Wisconsin");
Query OK, 1 row affected (0.00 sec)
          
mysql&#62; INSERT
INTO STATES VALUES (50, "WY", "Wyoming");
Query OK, 1 row affected (0.00 sec)
        
      
    
    
The complete INSERT statement is available in TOTD
#38. Most of this step can be executed from within the IDE as
well as explained in TOTD
#38. 
  Download and unzip GlassFish v3 build
58. Copy the latest MySQL
Connector/J
jar in "domains/domain1/lib" directory of GlassFish and start the
application server
as:
    
    
      
        
          ~/tools/glassfish/v3/58/glassfishv3/bin &#62;asadmin start-domain
        
      
    
  
  Create JDBC connection pool and JNDI resource as shown
below:
    
    
      
        
          ~/tools/glassfish/v3/58/glassfishv3/bin &#62;./asadmin
create-jdbc-connection-pool --datasourceclassname
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype
javax.sql.DataSource --property
"User=duke:Password=glassfish:URL=jdbc\:mysql\://localhost/states"
jdbc/states
          
Command create-jdbc-connection-pool executed successfully.
~/tools/glassfish/v3/58/glassfishv3/bin &#62;./asadmin ping-connection-pool
jdbc/states
          
Command ping-connection-pool executed successfully.
~/tools/glassfish/v3/58/glassfishv3/bin &#62;./asadmin create-jdbc-resource
--connectionpoolid jdbc/states jdbc/jndi_states
          
Command create-jdbc-resource executed successfully.
        
      
    
    
  
  Download NetBeans
6.8 M1 and install "All" version. Expand "Servers" node and
add the recently installed GlassFish server.
  Create a new Web project and name it "HelloEclipseLink".
Make sure to choose "GlassFish v3" as the server and "Java EE 6 Web" as
the Java EE version as shown below:
    
    
    
Take defaults elsewhere.
  Create the Persistence Unit
  
    Right-click on the newly created project and select
"New", "Entity Classes from Database ...". Choose the earlier created
data source "jdbc/jndi_states" as shown below:
      
      
    Select "STATES" table in "Available Tables:" and click on
"Add &#62;" and then "Next &#62;".
    Click on "Create Persistence Unit ...", take all the
defaults and click on "Create". "EclipseLink" is the Reference
Implementation for JPA 2.0 is the default choosen Persistence Provider
as shown below:
      
      
    Enter the package name as "server" and click on "Finish".
  
  Create a Servlet to retrieve and display all the
information from the database
  
    Right click on the project, "New", "Servlet ...".
    Give the Servlet name "ShowStates" and package "server".
    Even
though you can take all the defaults and click on "Finish" but instead
click on "Next &#62;" and the following screen is shown:
      
      
      
Notice
"Add information to deployment descriptor (web.xml)" checkbox. Servlet
3.0 makes "web.xml" optional in most of the common cases by providing
corresponding annotations and NetBeans 6.8 leverages that
functionality. As a result, no "web.xml" will be bundled in our WAR
file. Click on "Finish" now.
      
The generated servlet code looks like:
      
      
      
Notice @WebServlet annotation, this makes "web.xml" optional. TOTD
#82 provide another example on how to use Servlet 3.0 with
EJB 3.1.
    Inject the Persistence Unit as:
      
      
        
          
            &#160;&#160;&#160; @PersistenceUnit
&#160;&#160;&#160; EntityManagerFactory emf;
          
        
      
      
right above "processRequest" method.
    Change the "try" block of "processRequest" method to:
      
      
        
          
            &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
List&#60;States&#62; list =
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
out.println("&#60;table border=\"1\"&#62;");
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
for (States state : list) {
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
out.println("&#60;tr&#62;&#60;td&#62;" + state.getAbbrev() +
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
"&#60;/td&#62;&#60;td&#62;" + state.getName() +
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
"&#60;/td&#62;&#60;/tr&#62;");
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
}
&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;
out.println("&#60;/table&#62;");
          
        
      
      
This uses a predefined query to retrieve all rows from the table and
then display them in a simple formatted HTML table.
  
  Run the project
  
  
  
    Right click on the project, select "Properties" and
change the "Relative URL" to "/ShowStates". This is the exact URL that
you specified earlier.
      
      
    Right-click on the project and select "Run" to see the
following output:
      
      
      
    
  

So we created a simple web application that uses Servlet 3.0, JPA 2.0,
EclipseLink and deployed on GlassFish v3 using NetBeans 6.8 M1.
NetBeans provides reasonable defaults making you a lazy programmer.
Believe this is more evident when you start playing with Java EE
support in other IDEs ;-)

Finally, lets look at the structure of the generated WAR file:



It's very clean - no "web.xml", only the relevant classes and
"persistence.xml".

Also refer to other Java EE 6
blog entries. A future blog entry will show how to use JSF
2.0 instead of Servlet for displaying the results.

Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available here.


Technorati: totd
glassfish
v3 mysql javaee6 servlet3
jpa2 netbeans]]></description>
			<content:encoded><![CDATA[<br>
<a href="http://www.netbeans.org/servlets/NewsItemView?newsItemID=1413">NetBeans
6.8 M1</a> introduces support for creating Java EE 6 applications
... cool!<br>
<br>
This <span>T</span>ip <span>O</span>f <span>T</span>he <span>D</span>ay (TOTD) shows how
to create a simple web application using JPA 2.0 and Servlet 3.0 and
deploy on GlassFish v3 <a href="http://download.java.net/glassfish/v3/promoted/">latest
promoted build</a> (<a href="http://download.java.net/glassfish/v3/promoted/glassfish-v3-preview-b58.zip">58</a>
as of this writing). If you can work with the one week older build then
NetBeans 6.8 M1 comes pre-bundled with 57. The example below should
work fine on that as well.<br>
<ol>
  <li>Create the database, table, and populate some data into it
as shown below:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>~/tools/glassfish/v3/58/glassfishv3/bin&nbsp;&gt;<span>sudo mysql --user root</span><br>
Password:<br>
Welcome to the MySQL monitor.&nbsp; Commands end with ; or \g.<br>
Your MySQL connection id is 1592<br>
Server version: 5.1.30 MySQL Community Server (GPL)<br>
          <br>
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.<br>
          <br>
mysql&gt; <span>create
database states;</span><br>
Query OK, 1 row affected (0.02 sec)<br>
          <br>
mysql&gt; <span>CREATE
USER duke IDENTIFIED by 'glassfish';</span><br>
Query OK, 0 rows affected (0.00 sec)<br>
          <br>
mysql&gt; <span>GRANT ALL
on states.* TO duke;</span><br>
Query OK, 0 rows affected (0.24 sec)<br>
          <br>
mysql&gt; <span>use states;</span><br>
          <span>Database changed</span><br>
          <br>
mysql&gt; <span>CREATE
TABLE STATES (</span><br>
          <span>&nbsp;&nbsp;&nbsp;
-&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
id INT,</span><br>
          <span>&nbsp;&nbsp;&nbsp;
-&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
abbrev VARCHAR(2),</span><br>
          <span>&nbsp;&nbsp;&nbsp;
-&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
name VARCHAR(50),</span><br>
          <span>&nbsp;&nbsp;&nbsp;
-&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
PRIMARY KEY (id)</span><br>
          <span>&nbsp;&nbsp;&nbsp;
-&gt; );</span><br>
Query OK, 0 rows affected (0.16 sec)<br>
          <br>
mysql&gt; <span>INSERT
INTO STATES VALUES (1, "AL", "Alabama");</span><br>
          <span>INSERT INTO
STATES VALUES (2, "AK", "Alaska");</span><br>
          <br>
. . .<br>
          <br>
mysql&gt; <span>INSERT
INTO STATES VALUES (49, "WI", "Wisconsin");</span><br>
Query OK, 1 row affected (0.00 sec)<br>
          <br>
mysql&gt; <span>INSERT
INTO STATES VALUES (50, "WY", "Wyoming");</span><br>
Query OK, 1 row affected (0.00 sec)</td>
        </tr>
      </tbody>
    </table>
    <br>
The complete INSERT statement is available in <a href="http://blogs.sun.com/arungupta/entry/totd_38_creating_a_mysql">TOTD
#38</a>. Most of this step can be executed from within the IDE as
well as explained in <a href="http://blogs.sun.com/arungupta/entry/totd_38_creating_a_mysql">TOTD
#38</a>. </li>
  <li>Download and unzip GlassFish v3 <a href="http://download.java.net/glassfish/v3/promoted/glassfish-v3-preview-b58.zip">build
58</a>. Copy the latest <a href="http://dev.mysql.com/downloads/connector/j/5.1.html">MySQL
Connector/J</a>
jar in "domains/domain1/lib" directory of GlassFish and start the
application server
as:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>~/tools/glassfish/v3/58/glassfishv3/bin &gt;<span>asadmin start-domain</span></td>
        </tr>
      </tbody>
    </table>
  </li>
  <li>Create JDBC connection pool and JNDI resource as shown
below:<br>
    <br>
    <table
 cellpadding="2" cellspacing="2">
      <tbody>
        <tr>
          <td>~/tools/glassfish/v3/58/glassfishv3/bin &gt;<span>./asadmin
create-jdbc-connection-pool --datasourceclassname
com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource --restype
javax.sql.DataSource --property
"User=duke:Password=glassfish:URL=jdbc\:mysql\://localhost/states"
jdbc/states</span><br>
          <br>
Command create-jdbc-connection-pool executed successfully.<br>
~/tools/glassfish/v3/58/glassfishv3/bin &gt;<span>./asadmin ping-connection-pool
jdbc/states</span><br>
          <br>
Command ping-connection-pool executed successfully.<br>
~/tools/glassfish/v3/58/glassfishv3/bin &gt;<span>./asadmin create-jdbc-resource
--connectionpoolid jdbc/states jdbc/jndi_states</span><br>
          <br>
Command create-jdbc-resource executed successfully.</td>
        </tr>
      </tbody>
    </table>
    <br>
  </li>
  <li>Download <a href="http://bits.netbeans.org/netbeans/6.8/m1/">NetBeans
6.8 M1</a> and install "All" version. Expand "Servers" node and
add the recently installed GlassFish server.</li>
  <li>Create a new Web project and name it "HelloEclipseLink".
Make sure to choose "GlassFish v3" as the server and "Java EE 6 Web" as
the Java EE version as shown below:<br>
    <br>
    <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-javaee6web.png" /><br>
    <br>
Take defaults elsewhere.</li>
  <li>Create the Persistence Unit</li>
  <ol>
    <li>Right-click on the newly created project and select
"New", "Entity Classes from Database ...". Choose the earlier created
data source "jdbc/jndi_states" as shown below:<br>
      <br>
      <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-datasource.png" /></li>
    <li>Select "STATES" table in "Available Tables:" and click on
"Add &gt;" and then "Next &gt;".</li>
    <li>Click on "Create Persistence Unit ...", take all the
defaults and click on "Create". "EclipseLink" is the Reference
Implementation for JPA 2.0 is the default choosen Persistence Provider
as shown below:<br>
      <br>
      <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-pu.png" /></li>
    <li>Enter the package name as "server" and click on "Finish".</li>
  </ol>
  <li>Create a Servlet to retrieve and display all the
information from the database</li>
  <ol>
    <li>Right click on the project, "New", "Servlet ...".</li>
    <li>Give the Servlet name "ShowStates" and package "server".</li>
    <li>Even
though you can take all the defaults and click on "Finish" but instead
click on "Next &gt;" and the following screen is shown:<br>
      <br>
      <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-servlet-deployment.png" /><br>
      <br>
Notice
"Add information to deployment descriptor (web.xml)" checkbox. Servlet
3.0 makes "web.xml" optional in most of the common cases by providing
corresponding annotations and NetBeans 6.8 leverages that
functionality. As a result, no "web.xml" will be bundled in our WAR
file. Click on "Finish" now.<br>
      <br>
The generated servlet code looks like:<br>
      <br>
      <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-servlet-annotations.png" /><br>
      <br>
Notice @WebServlet annotation, this makes "web.xml" optional. <a href="http://blogs.sun.com/arungupta/entry/totd_81_getting_started_with">TOTD
#82</a> provide another example on how to use Servlet 3.0 with
EJB 3.1.</li>
    <li>Inject the Persistence Unit as:<br>
      <br>
      <table
 cellpadding="2" cellspacing="2">
        <tbody>
          <tr>
            <td>&nbsp;&nbsp;&nbsp; @PersistenceUnit<br>
&nbsp;&nbsp;&nbsp; EntityManagerFactory emf;</td>
          </tr>
        </tbody>
      </table>
      <br>
right above "processRequest" method.</li>
    <li>Change the "try" block of "processRequest" method to:<br>
      <br>
      <table
 cellpadding="2" cellspacing="2">
        <tbody>
          <tr>
            <td>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
List&lt;States&gt; list =
emf.createEntityManager().createNamedQuery("States.findAll").getResultList();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
out.println("&lt;table border=\"1\"&gt;");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
for (States state : list) {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
out.println("&lt;tr&gt;&lt;td&gt;" + state.getAbbrev() +<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"&lt;/td&gt;&lt;td&gt;" + state.getName() +<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
"&lt;/td&gt;&lt;/tr&gt;");<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
}<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
out.println("&lt;/table&gt;");</td>
          </tr>
        </tbody>
      </table>
      <br>
This uses a predefined query to retrieve all rows from the table and
then display them in a simple formatted HTML table.</li>
  </ol>
  <li>Run the project</li>
  <ol>
  </ol>
  <ol>
    <li>Right click on the project, select "Properties" and
change the "Relative URL" to "/ShowStates". This is the exact URL that
you specified earlier.<br>
      <br>
      <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-run.png" /></li>
    <li>Right-click on the project and select "Run" to see the
following output:<br>
      <br>
      <img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-output.png" /><br>
      <br>
    </li>
  </ol>
</ol>
So we created a simple web application that uses Servlet 3.0, JPA 2.0,
EclipseLink and deployed on GlassFish v3 using NetBeans 6.8 M1.
NetBeans provides reasonable defaults making you a lazy programmer.
Believe this is more evident when you start playing with Java EE
support in other IDEs ;-)<br>
<br>
Finally, lets look at the structure of the generated WAR file:<br>
<br>
<img alt="" src="http://blogs.sun.com/arungupta/resource/images/nb68m1-jpa-dir-structure.png" /><br>
<br>
It's very clean - no "web.xml", only the relevant classes and
"persistence.xml".<br>
<br>
Also refer to other <a href="http://blogs.sun.com/arungupta/tags/javaee6">Java EE 6
blog entries</a>. A future blog entry will show how to use JSF
2.0 instead of Servlet for displaying the results.<br>
<br>
Please leave suggestions on other TOTD that
you'd like to see.
A complete archive of all the tips is available <a href="http://blogs.sun.com/arungupta/tags/totd">here</a>.
<br>
<br>
<small>Technorati: <a href="http://technorati.com/tags/totd">totd</a>
<a href="http://technorati.com/tags/glassfish">glassfish</a>
<a href="http://technorati.com/tags/v3">v3</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/javaee6">javaee6</a> <a href="http://technorati.com/tags/servlet3">servlet3</a>
<a href="http://technorati.com/tags/jpa2">jpa2</a> <a href="http://technorati.com/tags/netbeans">netbeans</a></small><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20629&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20629&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2009/08/13/totd-93-getting-started-with-java-ee-6-using-netbeans-6-8-m1-glassfish-v3-a-simple-servlet-3-0-jpa-2-0-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

