<?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; sakila</title>
	<atom:link href="http://planetmysql.ru/category/sakila/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Thu, 29 Jul 2010 23:40:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<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&amp;utm_medium=rss&amp;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[General]]></category>
		<category><![CDATA[eclipselink]]></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://blogs.sun.com/arungupta/entry/totd_122_creating_a_jpa/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&amp;utm_medium=rss&amp;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://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
