<?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; jpa</title>
	<atom:link href="http://planetmysql.ru/category/jpa/feed/" rel="self" type="application/rss+xml" />
	<link>http://planetmysql.ru</link>
	<description>Блог о самой популярной СУБД MySQL</description>
	<lastBuildDate>Fri, 10 Feb 2012 22:53:14 +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 #150: Collection of GlassFish, NetBeans, JPA, JSF, JAX-WS, EJB, Jersey, MySQL, Rails, Eclipse, and OSGi tips</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_150_collection_of_glassfish?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-150-collection-of-glassfish-netbeans-jpa-jsf-jax-ws-ejb-jersey-mysql-rails-eclipse-and-osgi-tips</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_150_collection_of_glassfish#comments</comments>
		<pubDate>Thu, 18 Nov 2010 14:00:23 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[eclipse]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jaxws]]></category>
		<category><![CDATA[jersey]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[jsf]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[osgi]]></category>
		<category><![CDATA[rails]]></category>
		<category><![CDATA[totd]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_150_collection_of_glassfish</guid>
		<description><![CDATA[This is the 150th tip published on this blog so decided to make it a collection of all the previous ones. Here is a tag cloud (created from wordle.net/create) from title of all the tips:

As expected GlassFish is the most prominent topic. And then there are several entries on NetBeans, JRuby/Rails, several Java EE 6 technologies like JPA, JAX-WS, JAX-RS, EJB, and JSF, and more entries on Eclipse, OSGi and some other tecnhologies too. Here is a complete collection of all the tips published so far:

    #149: How to clean IntelliJ cache, preferences, etc on Mac OS X ?
    #148: JPA2 Metamodel Classes in NetBeans 7.0 - Writing type-safe Criteria API
    #147: Java Server Faces 2.0 Composite Components using NetBeans - DRY your code
    #146: Understanding the EJB 3.1 Timer service in Java EE 6 - Programmatic, Deployment Descriptor, @Schedule
    #145: CDI Events - a light-weight producer/consumer in Java EE 6
    #144: CDI @Produces for container-managed @Resource
    #143: Retrieve Twitter user timeline using using Jersey and OAuth
    #142: GlassFish 3.1 - SSH Provisioning and Start/Stop instance/cluster on local/remote machines
    #141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2
    #140: Moving GlassFish Installation - Referenced file does not exist &#34;osgi-main.jar&#34;
    #139: Asynchronous Request Processing using Servlets 3.0 and Java EE 6
    #138: GlassFish 3.1 Milestone 1 - Clustering and Application Versioning Demos
    #137: Asynchronous EJB, a light-weight JMS solution - Feature-rich Java EE 6
    #136: Default Error Page using Servlets 3.0 - Improved productivity using Java EE 6
    #135: JSF2 Composite Components using NetBeans IDE - lightweight Java EE 6
    #134: Interceptors 1.1 in Java EE 6 - What and How ?
    #133: JPA2 (JPQL &#38; Criteria), JavaDB, and embedded GlassFish - perfect recipe for testing
    #132: Servlets 3.0 in Embedded GlassFish Reloaded - lightweight Java EE 6
    #131: Dynamic OSGi services in GlassFish - Using ServiceTracker
    #130: Invoking a OSGi service from a JAX-WS Endpoint - OSGi and Enterprise Java
    #129: Managed Beans 1.0 in Java EE 6 - What and How ?
    #128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3
    #127: Embedding GlassFish in an existing OSGi runtime - Eclipse Equinox
    #126: Creating an OSGi bundles using Eclipse and deploying in GlassFish
    #125: Creating an OSGi bundles using NetBeans and deploying in GlassFish
    #124: OSGi Declarative Services in GlassFish - Accessed from a Java EE client
    #124: Using CDI + JPA with JAX-RS and JAX-WS
    #123: f:ajax, Bean Validation for JSF, CDI for JSF and JPA 2.0 Criteria API - all in one Java EE 6 sample application
    #122: Creating a JPA Persistence Unit using NetBeans 6.8
    #121: JDBC resource for MySQL and Oracle sample database in GlassFish v3
    #120: Deployment Descriptor-free Java EE 6 application using JSF 2.0 + EJB 3.1 + Servlets 3.0
    #119: Telnet to GlassFish v3 with NetBeans 6.8 - &#34;Could not open connection to the host&#34;
    #118: Managing OSGi bundles in GlassFish v3 - asadmin, filesystem, telnet console, web browser, REST, osgish
    #117: Invoke a JAX-WS Web service from a Rails app deployed in GlassFish
    #116: GlassFish v3 Administration using JavaFX front-end - JNLP available
    #115: GlassFish in Eclipse - Integrated Bundle, Install Stand-alone or Update Existing plugin
    #114: How to enable Java Console in Mac OS X, Windows, ... ?
    #113: JavaFX front-end for GlassFish v3 Administration - Using REST interface
    #112: Exposing Oracle database tables as RESTful entities using JAX-RS, GlassFish, and NetBeans
    #111: Rails Scaffold for a pre-existing table using Oracle and GlassFish
    #110: JRuby on Rails application using Oracle on GlassFish
    #109: How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?
    #108: Java EE 6 web application (JSF 2.0 + JPA 2.0 + EJB 3.1) using Oracle, NetBeans, and GlassFish
    #107: Connect to Oracle database using NetBeans
    #106: How to install Oracle Database 10g on Mac OS X (Intel) ?
    TOTD #105: GlassFish v3 Monitoring – How to monitor a Rails app using asadmin, JavaScript, jConsole, REST ?
    #104: Popular Ruby-on-Rails applications on GlassFish v3 – Redmine, Typo, Substruct
    #103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish
    #102: Java EE 6 (Servlet 3.0 and EJB 3.1) wizards in Eclipse
    #101: Applying Servlet 3.0/Java EE 6 “web-fragment.xml” to Lift – Deploy on GlassFish v3
    #100: Getting Started with Scala Lift on GlassFish v3
    #99: Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse
    #98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse
    #97: GlassFish Plugin with Eclipse 3.5
    #96: GlassFish v3 REST Interface to Monitoring and Management - JSON, XML, and HTML representations
    #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 &#38; GlassFish v3
    #94: A simple Java Server Faces 2.0 + JPA 2.0 application - Getting Started with Java EE 6 using NetBeans 6.8 M1 &#38; GlassFish v3
    #93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &#38; GlassFish v3 - A simple Servlet 3.0 + JPA 2.0 app
    #92: Session Failover for Rails applications running on GlassFish
    #91: Applying Java EE 6 &#34;web-fragment.xml&#34; to Apache Wicket - Deploy on GlassFish v3
    #90: Migrating from Wicket 1.3.x to 1.4 - &#34;Couldn't load DiskPageStore index from file&#34; error
    #89: How to add pagination to an Apache Wicket application
    #88: How add pagination to Rails - will_paginate
    #87: How to fix the error undefined method `new' for &#34;Rack::Lock&#34;:String caused by Warbler/JRuby-Rack ?
    #86: Getting Started with Apache Wicket on GlassFish
    #85: Getting Started with Django Applications on GlassFish v3
    #84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish
    #83: Eclipse Tools Bundle for GlassFish 1.0 - Now Available!
    #82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7
    #81: How to use nginx to load balance a cluster of GlassFish Gem ?
    #80: Sinatra CRUD application using Haml templates with JRuby and GlassFish Gem
    #79: Getting Started with Sinatra applications on JRuby and GlassFish Gem
    #78: GlassFish, EclipseLink, and MySQL efficient pagination using LIMIT
    #77: Running Seam examples with GlassFish
    #76: JRuby 1.2, Rails 2.3, GlassFish Gem 0.9.3, ActiveRecord JDBC Adapter 0.9.1 - can they work together ?
    #75: Getting Started with Grails using GlassFish v3 Embedded
    #74: JRuby and GlassFish Integration Test #5: JRuby 1.2.0 RC2 + Rails 2.x.x + GlassFish + Redmine
    #73: JRuby and GlassFish Integration Test #4: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v2 + Warbler
    #72: JRuby and GlassFish Integration Test #3: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v3
    #71: JRuby and GlassFish Integration Test #2: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish v3 Prelude
    #70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem
    #69: GlassFish High Availability/Clustering using Sun Web Server + Load Balancer Plugin on Windows Vista
    #68: Installing Zones in Open Solaris 2008/11 on Virtual Box
    #67: How to front-end a GlassFish Cluster with Apache + mod_jk on Mac OSX Leopard ?
    #66: GlassFish Eclipse Plugin 1.0.16 - Install v3 Prelude from the IDE
    #65: Windows 7 Beta 1 Build 7000 on Virtual Box: NetBeans + Rails + GlassFish + MySQL
    #64: OpenSolaris 2008/11 using Virtual Box
    #63: jmx4r gem - How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?
    #62: How to remotely manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX API ?
    #61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?
    #60: Configure MySQL 6.0.x-alpha to NetBeans 6.5
    #59: How to add Twitter feeds to blogs.sun.com ? + Other Twitter Tools
    #58: Jersey and GlassFish - how to process POST requests ?
    #57: Jersey Client API - simple and easy to use
    #56: Simple RESTful Web service using Jersey and Embeddable GlassFish - Text and JSON output
    #55: How to build GlassFish v3 Gem ?
    #54: Java Server Faces with Eclipse IDE
    #53: Scaffold in Merb using JRuby/GlassFish
    #52: Getting Started with Merb using GlassFish Gem
    #51: Embedding Google Maps in Java Server Faces using GMaps4JSF
    #50: Mojarra 2.0 EDR2 is now available - Try them with GlassFish v3 and NetBeans 6.5
    #49: Converting a JSF 1.2 application to JSF 2.0 - @ManagedBean
    #48: Converting a JSF 1.2 application to JSF 2.0 - Facelets and Ajax
    #47: Getting Started with Mojarra 2.0 nightly on GlassFish v2
    #46: Facelets with Java Server Faces 1.2
    #45: Ajaxifying Java Server Faces using JSF Extensions
    #44: JDBC Connection Pooling for Rails on GlassFish v3
    #43: GlassFish v3 Build Flavors
    #42: Hello JavaServer Faces World with NetBeans and GlassFish
    #41: How I created transparent logo of GlassFish using Gimp ?
    #40: jQuery Autcomplete widget with MySQL, GlassFish, NetBeans
    #39: Prototype/Script.aculo.us Autcomplete widget with MySQL, GlassFish, NetBeans
    #38: Creating a MySQL Persistence Unit using NetBeans IDE
    #37: SQLite3 with Ruby-on-Rails on GlassFish Gem
    #36: Writing First Test for a Rails Application
    #35: Rails Database Connection on Solaris
    #34: Using Felix Shell with GlassFish
    #33: Building GlassFish v3 Workspace
    #32: Rails Deployment on GlassFish v3 from NetBeans IDE
    #31: CRUD Application using Grails - Hosted on GlassFish and MySQL
    #30: CRUD Application using Grails - Hosted on Jetty and HSQLDB
    #29: Enabling &#34;Available Plugins&#34; tab in NetBeans IDE
    #28: Getting Started with Rails 2.0 Scaffold
    #27: Configurable Multiple Ruby Platforms in NetBeans 6.1 M1
    #26: Overriding Database Defaults in Rails 2.0.2
    #25: Rails application with PostgreSQL database using NetBeans
    #24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1
    #23: JavaFX Client invoking a Metro endpoint
    #22: Java SE client for a Metro endpoint
    #21: Metro 1.1 with GlassFish v2 UR1 and NetBeans 6
    #20: How to create a new jMaki widget ?
    #19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?
    #18: How to Build The GlassFish v3 Gem for JRuby ?
    #17: Backing Up your Blog Posts on Roller
    #16: Optimizing Metro Stubs by locally packaging the WSDL
    #15: Delete/Update Row from Database using jMaki Data Table
    #14: How to generate JRuby-on-Rails Controller on Windows (#9893)
    #13: Setup Mongrel for JRuby-on-Rails applications on Windows
    #12: Invoking a Java EE 5 Web service endpoint from JRuby
    #11: Setup Mongrel cluster for JRuby-on-Rails applications on Unix
    #10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget
    #9: Using JDBC connection pool/JNDI name from GlassFish in Rails Application
    #8: Generating JSON using JAXB annotations in Jersey
    #7: Switch between JRuby and CRuby interpreter in NetBeans 6
    #6: Difference between Ruby Gem and Rails Plugin
    #5: Loading data from beans in jMaki widgets
    #4: How to convert a Session EJB to a Web service ?
    #3: Using JavaDB with JRuby on Rails
    #2: Change the endpoint address on a pre-generated Web services Stub
    #1: SOAP Messaging Logging in Metro

Just for fun, here is another tag cloud:

You can access all the tips here. And keep those suggestions coming!
Technorati: totd glassfish netbeans jpa jsf jaxws jersey mysql rails osgi eclipse]]></description>
			<content:encoded><![CDATA[<p>This is the 150th tip published on <a href="http://blogs.sun.com/arungupta">this blog</a> so decided to make it a collection of all <a href="http://blogs.sun.com/arungupta/tags/totd">the previous ones</a>. Here is a tag cloud (created from <a href="http://wordle.net/create">wordle.net/create</a>) from title of all the tips:</p>
<p><img height="259" style="margin: 5px" width="700" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/11/totd150-tag-cloud.png" /></p>
<p>As expected <a href="http://glassfish.org">GlassFish</a> is the most prominent topic. And then there are several entries on NetBeans, JRuby/Rails, several Java EE 6 technologies like JPA, JAX-WS, JAX-RS, EJB, and JSF, and more entries on Eclipse, OSGi and some other tecnhologies too. Here is a complete collection of all the tips published so far:</p>
<ul>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_149_how_to_clean">#149: How to clean IntelliJ cache, preferences, etc on Mac OS X ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_148_jpa2_metamodel_classes">#148: JPA2 Metamodel Classes in NetBeans 7.0 - Writing type-safe Criteria API</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_147_java_server_faces">#147: Java Server Faces 2.0 Composite Components using NetBeans - DRY your code</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_146_understanding_the_ejb">#146: Understanding the EJB 3.1 Timer service in Java EE 6 - Programmatic, Deployment Descriptor, @Schedule</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_145_cdi_events_a">#145: CDI Events - a light-weight producer/consumer in Java EE 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_144_cdi_produces_for">#144: CDI @Produces for container-managed @Resource</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_143_retrieve_twitter_user">#143: Retrieve Twitter user timeline using using Jersey and OAuth</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/ttod_142_glassfish_3_1">#142: GlassFish 3.1 - SSH Provisioning and Start/Stop instance/cluster on local/remote machines</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_141_running_glassfish_3">#141: Running GlassFish 3.1 on Ubuntu 10.04 AMI on Amazon EC2</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_140_moving_glassfish_installation">#140: Moving GlassFish Installation - Referenced file does not exist &quot;osgi-main.jar&quot;</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_139_asynchronous_request_processing">#139: Asynchronous Request Processing using Servlets 3.0 and Java EE 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_138_glassfish_3_1">#138: GlassFish 3.1 Milestone 1 - Clustering and Application Versioning Demos</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_137_asynchronous_ejb_a">#137: Asynchronous EJB, a light-weight JMS solution - Feature-rich Java EE 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_136_default_error_page">#136: Default Error Page using Servlets 3.0 - Improved productivity using Java EE 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_135_jsf2_custom_components">#135: JSF2 Composite Components using NetBeans IDE - lightweight Java EE 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_134_interceptors_1_1">#134: Interceptors 1.1 in Java EE 6 - What and How ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_133_jpa2_jpql_criteria">#133: JPA2 (JPQL &amp; Criteria), JavaDB, and embedded GlassFish - perfect recipe for testing</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_132_servlets_3_0">#132: Servlets 3.0 in Embedded GlassFish Reloaded - lightweight Java EE 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_131_dynamic_osgi_services">#131: Dynamic OSGi services in GlassFish - Using ServiceTracker</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_130_invoking_a_osgi">#130: Invoking a OSGi service from a JAX-WS Endpoint - OSGi and Enterprise Java</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_129_managed_beans_1">#129: Managed Beans 1.0 in Java EE 6 - What and How ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_128_ejbcontainer_createejbcontainer_embedded">#128: EJBContainer.createEJBContainer: Embedded EJB using GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_127_embedding_glassfish_in">#127: Embedding GlassFish in an existing OSGi runtime - Eclipse Equinox</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_126_creating_an_osgi">#126: Creating an OSGi bundles using Eclipse and deploying in GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_125_creating_an_osgi">#125: Creating an OSGi bundles using NetBeans and deploying in GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_124_osgi_declarative_services">#124: OSGi Declarative Services in GlassFish - Accessed from a Java EE client</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_124_using_cdi_jpa">#124: Using CDI + JPA with JAX-RS and JAX-WS</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_123_f_ajax_bean">#123: f:ajax, Bean Validation for JSF, CDI for JSF and JPA 2.0 Criteria API - all in one Java EE 6 sample application</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_122_creating_a_jpa">#122: Creating a JPA Persistence Unit using NetBeans 6.8</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/ttd_121_jdbc_resource_for">#121: JDBC resource for MySQL and Oracle sample database in GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_120_deployment_descriptor_free">#120: Deployment Descriptor-free Java EE 6 application using JSF 2.0 + EJB 3.1 + Servlets 3.0</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_119_telnet_to_glassfish">#119: Telnet to GlassFish v3 with NetBeans 6.8 - &quot;Could not open connection to the host&quot;</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_118_managing_osgi_bundles">#118: Managing OSGi bundles in GlassFish v3 - asadmin, filesystem, telnet console, web browser, REST, osgish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_117_invoke_a_jax">#117: Invoke a JAX-WS Web service from a Rails app deployed in GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_116_glassfish_v3_administration">#116: GlassFish v3 Administration using JavaFX front-end - JNLP available</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_115_glassfish_in_eclipse">#115: GlassFish in Eclipse - Integrated Bundle, Install Stand-alone or Update Existing plugin</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_114_how_to_enable">#114: How to enable Java Console in Mac OS X, Windows, ... ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_113_javafx_front_end">#113: JavaFX front-end for GlassFish v3 Administration - Using REST interface</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_112_exposing_oracle_database">#112: Exposing Oracle database tables as RESTful entities using JAX-RS, GlassFish, and NetBeans</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/http_blog_arungupta_me_2009">#111: Rails Scaffold for a pre-existing table using Oracle and GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_110_jruby_on_rails">#110: JRuby on Rails application using Oracle on GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_109_how_to_convert">#109: How to convert a JSF managed bean to JSR 299 bean (Web Beans) ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_108_java_ee_6">#108: Java EE 6 web application (JSF 2.0 + JPA 2.0 + EJB 3.1) using Oracle, NetBeans, and GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_107_connect_to_oracle">#107: Connect to Oracle database using NetBeans</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_105_how_to_install">#106: How to install Oracle Database 10g on Mac OS X (Intel) ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_104_glassfish_v3_monitoring">TOTD #105: GlassFish v3 Monitoring – How to monitor a Rails app using asadmin, JavaScript, jConsole, REST ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/popular_ruby_on_rails_applications">#104: Popular Ruby-on-Rails applications on GlassFish v3 – Redmine, Typo, Substruct</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_103_glassfish_v3_with">#103: GlassFish v3 with different OSGi runtimes – Felix, Equinox, and Knoplerfish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_102_java_ee_6">#102: Java EE 6 (Servlet 3.0 and EJB 3.1) wizards in Eclipse</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_101_applying_servlet_3">#101: Applying Servlet 3.0/Java EE 6 “web-fragment.xml” to Lift – Deploy on GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_100_getting_started_with">#100: Getting Started with Scala Lift on GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java">#99: Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_98_create_a_metro">#98: Create a Metro JAX-WS Web service using GlassFish Tools Bundle for Eclipse</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_97_glassfish_plugin_with">#97: GlassFish Plugin with Eclipse 3.5</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_96_glassfish_v3_rest">#96: GlassFish v3 REST Interface to Monitoring and Management - JSON, XML, and HTML representations</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_95_ejb_3_1">#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 &amp; GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_94_a_simple_java">#94: A simple Java Server Faces 2.0 + JPA 2.0 application - Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_93_getting_started_with">#93: Getting Started with Java EE 6 using NetBeans 6.8 M1 &amp; GlassFish v3 - A simple Servlet 3.0 + JPA 2.0 app</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_92_session_failover_for">#92: Session Failover for Rails applications running on GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_91_applying_java_ee">#91: Applying Java EE 6 &quot;web-fragment.xml&quot; to Apache Wicket - Deploy on GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_90_migrating_from_wicket">#90: Migrating from Wicket 1.3.x to 1.4 - &quot;Couldn't load DiskPageStore index from file&quot; error</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_89_how_to_add">#89: How to add pagination to an Apache Wicket application</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_88_how_add_pagination">#88: How add pagination to Rails - will_paginate</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_87_how_to_fix">#87: How to fix the error undefined method `new' for &quot;Rack::Lock&quot;:String caused by Warbler/JRuby-Rack ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_86_getting_started_with">#86: Getting Started with Apache Wicket on GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_85_getting_started_with">#85: Getting Started with Django Applications on GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_84_using_apache_mod">#84: Using Apache + mod_proxy_balancer to load balance Ruby-on-Rails running on GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_82_eclipse_tools_bundle">#83: Eclipse Tools Bundle for GlassFish 1.0 - Now Available!</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_81_getting_started_with">#82: Getting Started with Servlet 3.0 and EJB 3.1 in Java EE 6 using NetBeans 6.7</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_81_how_to_use">#81: How to use nginx to load balance a cluster of GlassFish Gem ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_80_sinatra_crud_application">#80: Sinatra CRUD application using Haml templates with JRuby and GlassFish Gem</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_79_getting_started_with">#79: Getting Started with Sinatra applications on JRuby and GlassFish Gem</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_78_glassfish_eclipselink_and">#78: GlassFish, EclipseLink, and MySQL efficient pagination using LIMIT</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_77_running_seam_examples">#77: Running Seam examples with GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_76_jruby_1_2">#76: JRuby 1.2, Rails 2.3, GlassFish Gem 0.9.3, ActiveRecord JDBC Adapter 0.9.1 - can they work together ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_75_getting_started_with">#75: Getting Started with Grails using GlassFish v3 Embedded</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_74_jruby_and_glassfish">#74: JRuby and GlassFish Integration Test #5: JRuby 1.2.0 RC2 + Rails 2.x.x + GlassFish + Redmine</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_73_jruby_and_glassfish">#73: JRuby and GlassFish Integration Test #4: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v2 + Warbler</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_72_jruby_and_glassfish">#72: JRuby and GlassFish Integration Test #3: JRuby 1.2.0 RC2 + Rails 2.2.x + GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_71_jruby_and_glassfish">#71: JRuby and GlassFish Integration Test #2: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish v3 Prelude</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_70_jruby_and_glassfish">#70: JRuby and GlassFish Integration Test# 1: JRuby 1.2.0 RC1 + Rails 2.2.x + GlassFish Gem</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_69_glassfish_high_availability">#69: GlassFish High Availability/Clustering using Sun Web Server + Load Balancer Plugin on Windows Vista</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_68_installing_zones_in">#68: Installing Zones in Open Solaris 2008/11 on Virtual Box</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_67_how_to_front">#67: How to front-end a GlassFish Cluster with Apache + mod_jk on Mac OSX Leopard ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_66_glassfish_eclipse_plugin">#66: GlassFish Eclipse Plugin 1.0.16 - Install v3 Prelude from the IDE</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_65_windows_7_beta">#65: Windows 7 Beta 1 Build 7000 on Virtual Box: NetBeans + Rails + GlassFish + MySQL</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_64_opensolaris_2008_11">#64: OpenSolaris 2008/11 using Virtual Box</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_63_jmx4r_gem_how">#63: jmx4r gem - How to manage/monitor your Rails/Merb applications on JRuby/GlassFish ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_62_how_to_remotely">#62: How to remotely manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX API ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_61_how_to_locally">#61: How to locally manage/monitor your Rails/Merb applications on JRuby/GlassFish using JMX ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_60_configure_mysql_6">#60: Configure MySQL 6.0.x-alpha to NetBeans 6.5</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_59_how_to_add">#59: How to add Twitter feeds to blogs.sun.com ? + Other Twitter Tools</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_58_jersey_and_glassfish">#58: Jersey and GlassFish - how to process POST requests ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_57_jersey_client_api">#57: Jersey Client API - simple and easy to use</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_56_simple_restful_web">#56: Simple RESTful Web service using Jersey and Embeddable GlassFish - Text and JSON output</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_55_how_to_build">#55: How to build GlassFish v3 Gem ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_54_java_server_faces">#54: Java Server Faces with Eclipse IDE</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_53_scaffold_in_merb">#53: Scaffold in Merb using JRuby/GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/getting_started_with_merb_using">#52: Getting Started with Merb using GlassFish Gem</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_51_embedding_google_maps">#51: Embedding Google Maps in Java Server Faces using GMaps4JSF</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_50_mojarra_2_0">#50: Mojarra 2.0 EDR2 is now available - Try them with GlassFish v3 and NetBeans 6.5</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_49_converting_a_jsf">#49: Converting a JSF 1.2 application to JSF 2.0 - @ManagedBean</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_48_converting_a_jsf">#48: Converting a JSF 1.2 application to JSF 2.0 - Facelets and Ajax</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_47_getting_started_with">#47: Getting Started with Mojarra 2.0 nightly on GlassFish v2</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_46_facelets_with_java">#46: Facelets with Java Server Faces 1.2</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_45_ajaxifying_java_server">#45: Ajaxifying Java Server Faces using JSF Extensions</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_44_jdbc_connection_pooling">#44: JDBC Connection Pooling for Rails on GlassFish v3</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_43_glassfish_v3_build">#43: GlassFish v3 Build Flavors</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_42_hello_javaserver_faces">#42: Hello JavaServer Faces World with NetBeans and GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_41_how_i_created">#41: How I created transparent logo of GlassFish using Gimp ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_40_jquery_autcomplete_widget">#40: jQuery Autcomplete widget with MySQL, GlassFish, NetBeans</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_39_prototype_script_aculo">#39: Prototype/Script.aculo.us Autcomplete widget with MySQL, GlassFish, NetBeans</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_38_creating_a_mysql">#38: Creating a MySQL Persistence Unit using NetBeans IDE</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_37_sqlite3_with_ruby">#37: SQLite3 with Ruby-on-Rails on GlassFish Gem</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_36_writing_first_test">#36: Writing First Test for a Rails Application</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_35_rails_database_connection">#35: Rails Database Connection on Solaris</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_34_using_felix_shell">#34: Using Felix Shell with GlassFish</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_33_building_glassfish_v3">#33: Building GlassFish v3 Workspace</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_32_rails_deployment_on">#32: Rails Deployment on GlassFish v3 from NetBeans IDE</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_31_crud_application_using">#31: CRUD Application using Grails - Hosted on GlassFish and MySQL</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_30_crud_application_using">#30: CRUD Application using Grails - Hosted on Jetty and HSQLDB</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_29_enabling_available_plugins">#29: Enabling &quot;Available Plugins&quot; tab in NetBeans IDE</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_28_getting_started_with">#28: Getting Started with Rails 2.0 Scaffold</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_27_configurable_multiple_ruby">#27: Configurable Multiple Ruby Platforms in NetBeans 6.1 M1</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_26_overriding_database_defaults">#26: Overriding Database Defaults in Rails 2.0.2</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_25_rails_application_with">#25: Rails application with PostgreSQL database using NetBeans</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_24_getting_started_with">#24: Getting Started with Rails 2.0.x in JRuby 1.0.3 and JRuby 1.1RC1</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_23_javafx_client_invoking">#23: JavaFX Client invoking a Metro endpoint</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_22_java_se_client">#22: Java SE client for a Metro endpoint</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_21_metro_1_1">#21: Metro 1.1 with GlassFish v2 UR1 and NetBeans 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_19_how_to_create">#20: How to create a new jMaki widget ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_18_how_to_add">#19: How to Add Metro Quality-of-Service to Contract-First Endpoint ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_18_how_to_build1">#18: How to Build The GlassFish v3 Gem for JRuby ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_17_backin_up_your">#17: Backing Up your Blog Posts on Roller</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_16_optimizing_metro_stubs">#16: Optimizing Metro Stubs by locally packaging the WSDL</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_15_delete_update_row">#15: Delete/Update Row from Database using jMaki Data Table</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_14_how_to_generate">#14: How to generate JRuby-on-Rails Controller on Windows (#9893)</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_13_setup_mongrel_for">#13: Setup Mongrel for JRuby-on-Rails applications on Windows</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_12_invoking_a_java">#12: Invoking a Java EE 5 Web service endpoint from JRuby</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_11_setup_mongrel_cluster">#11: Setup Mongrel cluster for JRuby-on-Rails applications on Unix</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_10_consuming_json_and">#10: Consuming JSON and XML representations generated by a Jersey endpoint in a jMaki Table widget</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_9_using_jdbc_connection">#9: Using JDBC connection pool/JNDI name from GlassFish in Rails Application</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_8_generating_json_using">#8: Generating JSON using JAXB annotations in Jersey</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_7_switch_between_jruby">#7: Switch between JRuby and CRuby interpreter in NetBeans 6</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_6_difference_between_ruby">#6: Difference between Ruby Gem and Rails Plugin</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_5_loading_data_from">#5: Loading data from beans in jMaki widgets</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_4_how_to_convert">#4: How to convert a Session EJB to a Web service ?</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_3_using_javadb_with">#3: Using JavaDB with JRuby on Rails</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_2_change_the_endpoint">#2: Change the endpoint address on a pre-generated Web services Stub</a></li>
    <li><a href="http://blogs.sun.com/arungupta/entry/totd_1_soap_messaging_logging">#1: SOAP Messaging Logging in Metro</a></li>
</ul>
<p>Just for fun, here is another tag cloud:</p>
<p><img height="264" style="margin: 5px" width="700" alt="" src="http://blog.arungupta.me/wp-content/uploads/2010/11/totd150-tag-cloud2.png" /></p>
<p>You can access all the tips <a href="http://blogs.sun.com/arungupta/tags/totd">here</a>. And keep those suggestions coming!</p>
<p><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/netbeans">netbeans</a> <a href="http://technorati.com/tags/jpa">jpa</a> <a href="http://technorati.com/tags/jsf">jsf</a> <a href="http://technorati.com/tags/jaxws">jaxws</a> <a href="http://technorati.com/tags/jersey">jersey</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/rails">rails</a> <a href="http://technorati.com/tags/osgi">osgi</a> <a href="http://technorati.com/tags/eclipse">eclipse</a></small></p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26501&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=26501&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/11/18/totd-150-collection-of-glassfish-netbeans-jpa-jsf-jax-ws-ejb-jersey-mysql-rails-eclipse-and-osgi-tips/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using ClusterJ (part of MySQL Cluster Connector for Java) – a tutorial</title>
		<link>http://www.clusterdb.com/mysql-cluster/using-clusterj-part-of-mysql-cluster-connector-for-java-a-tutorial/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=using-clusterj-part-of-mysql-cluster-connector-for-java-%25e2%2580%2593-a-tutorial</link>
		<comments>http://www.clusterdb.com/mysql-cluster/using-clusterj-part-of-mysql-cluster-connector-for-java-a-tutorial/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 12:40:27 +0000</pubDate>
		<dc:creator>Andrew Morgan</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[MySQL Cluster]]></category>
		<category><![CDATA[MySQL Cluster 7.1]]></category>
		<category><![CDATA[NDB API]]></category>

		<guid isPermaLink="false">http://www.clusterdb.com/?p=1008</guid>
		<description><![CDATA[Fig. 1 Java access to MySQL Cluster
ClusterJ is part of the MySQL Cluster Connector for Java which is currently in beta as part of MySQL Cluster 7.1. It is designed to provide a high performance method for Java applications to store and access data in a MySQL Cluster database. It is also designed to be easy for Java developers to use and is “in the style of” Hibernate/Java Data Objects (JDO) and JPA. It uses the Domain Object Model DataMapper pattern:

Data is represented as domain objects
Domain objects are separate from business logic
Domain objects are mapped to database tables

The purpose of ClusterJ is to provide a mapping from the table-oriented view of the data stored in MySQL Cluster to the Java objects used by the application. This is achieved by annotating interfaces representing the Java objects; where each persistent interface is mapped to a table and each property in that interface to a column. By default, the table name will match the interface name and the column names match the property names but this can be overridden using annotations.
Fig. 2 ClusterJ Interface Annotations
If the table does not already exist (for example, this is a brand new application with new data) then the table must be created manually &#8211; unlike OpenJPA, ClusterJ will not create the table automatically.
Figure 2 shows an example of an interface that has been created in order to represent the data held in the ‘employee’ table.
ClusterJ uses the following concepts:


Fig. 3 ClusterJ Terminology
SessionFactory: There is one instance per MySQL Cluster instance for each Java Virtual Machine (JVM). The SessionFactory object is used by the application to get hold of sessions. The configuration details for the ClusterJ instance are defined in the Configuration properties which is an artifact associated with the SessionFactory.
Session: There is one instance per user (per Cluster, per JVM) and represents a Cluster connection
Domain Object: Objects representing the data from a table. The domain objects (and their relationships to the Cluster tables) are defined by annotated interfaces (as shown in the right-hand side of Figure 2.
Transaction: There is one transaction per session at any point in time. By default, each operation (query, insert, update, or delete) is run under a new transaction. . The Transaction interface allows developers to aggregate multiple operations into a single, atomic unit of work.

ClusterJ will be suitable for many Java developers but it has some restrictions which may make OpenJPA with the ClusterJPA plug-in more appropriate. These ClusterJ restrictions are:

Persistent Interfaces rather than persistent classes. The developer provides the signatures for the getter/setter methods rather than the properties and no extra methods can be added.
No Relationships between properties or between objects can be defined in the domain objects. Properties are primitive types.
No Multi-table inheritance; there is a single table per persistent interface
No joins in queries (all data being queried must be in the same table/interface)
No Table creation &#8211; user needs to create tables and indexes
No Lazy Loading &#8211; entire record is loaded at one time, including large object (LOBs).

Tutorial
This tutorial uses MySQL Cluster 7.1.2a on Fedora 12. If using earlier or more recent versions of MySQL Cluster then you may need to change the class-paths as explained in http://dev.mysql.com/doc/ndbapi/en/mccj-using-clusterj.html
It is necessary to have MySQL Cluster up and running. For simplicity all of the nodes (processes) making up the Cluster will be run on the same physical host, along with the application.
These are the MySQL Cluster configuration files being used :
config.ini:
[ndbd default]noofreplicas=2
datadir=/home/billy/mysql/my_cluster/data

[ndbd]
hostname=localhost
id=3

[ndbd]
hostname=localhost
id=4

[ndb_mgmd]
id = 1
hostname=localhost
datadir=/home/billy/mysql/my_cluster/data

[mysqld]
hostname=localhost
id=101

[api]
hostname=localhost
my.cnf:
[mysqld]
ndbcluster
datadir=/home/billy/mysql/my_cluster/data
basedir=/usr/local/mysql
This tutorial focuses on ClusterJ rather than on running MySQL Cluster; if you are new to MySQL Cluster then refer to running a simple Cluster before trying this tutorial.
ClusterJ needs to be told how to connect to our MySQL Cluster database; including the connect string (the address/port for the management node), the database to use, the user to login as and attributes for the connection such as the timeout values. If these parameters aren’t defined then ClusterJ will fail with run-time exceptions. This information represents the “configuration properties” shown in Figure 3.  These parameters can be hard coded in the application code but it is more maintainable to create a clusterj.properties file that will be imported by the application. This file should be stored in the same directory as your application source code.
clusterj.properties:
com.mysql.clusterj.connectstring=localhost:1186
 com.mysql.clusterj.database=clusterdb
 com.mysql.clusterj.connect.retries=4
 com.mysql.clusterj.connect.delay=5
 com.mysql.clusterj.connect.verbose=1
 com.mysql.clusterj.connect.timeout.before=30
 com.mysql.clusterj.connect.timeout.after=20
 com.mysql.clusterj.max.transactions=1024
 com.mysql.clusterj.username=
 com.mysql.clusterj.password=
As ClusterJ will not create tables automatically, the next step is to create ‘clusterdb’ database (referred to in clusterj.properties) and the ‘employee’ table:
[billy@ws1 ~]$ mysql -u root -h 127.0.0.1 -P 3306 -u root
 mysql&#62;  create database clusterdb;use clusterdb;
 mysql&#62; CREATE TABLE employee (
 -&#62;     id INT NOT NULL PRIMARY KEY,
 -&#62;     first VARCHAR(64) DEFAULT NULL,
 -&#62;     last VARCHAR(64) DEFAULT NULL,
 -&#62;     municipality VARCHAR(64) DEFAULT NULL,
 -&#62;     started VARCHAR(64) DEFAULT NULL,
 -&#62;     ended  VARCHAR(64) DEFAULT NULL,
 -&#62;     department INT NOT NULL DEFAULT 1,
 -&#62;     UNIQUE KEY idx_u_hash (first,last) USING HASH,
 -&#62;     KEY idx_municipality (municipality)
 -&#62; ) ENGINE=NDBCLUSTER;
The next step is to create the annotated interface:
Employee.java:
import com.mysql.clusterj.annotation.Column;
import com.mysql.clusterj.annotation.Index;
import com.mysql.clusterj.annotation.PersistenceCapable;
import com.mysql.clusterj.annotation.PrimaryKey;
@PersistenceCapable(table="employee")
@Index(name="idx_uhash")
public interface Employee {
@PrimaryKey
int getId();
void setId(int id);
String getFirst();
void setFirst(String first);

String getLast();
void setLast(String last);
@Column(name="municipality")
@Index(name="idx_municipality")
String getCity();
void setCity(String city);
String getStarted();
void setStarted(String date);
String getEnded();
void setEnded(String date);
Integer getDepartment();
void setDepartment(Integer department);
}
The name of the table is specified in the annotation @PersistenceCapable(table=&#8221;employee&#8221;) and then each column from the employee table has an associated getter and setter method defined in the interface. By default, the property name in the interface is the same as the column name in the table – the column name has been overridden for the City property by explicitly including the @Column(name=&#8221;municipality&#8221;) annotation just before the associated getter method. The @PrimaryKey annotation is used to identify the property whose associated column is the Primary Key in the table. ClusterJ is made aware of the existence of indexes in the database using the @Index annotation.
The next step is to write the application code which we step through here block by block; the first of which simply contains the import statements and then loads the contents of the clusterj.properties defined above (Note – refer to section 3.2.1 for details on compiling and running the tutorial code):
Main.java (part 1):
import com.mysql.clusterj.ClusterJHelper;
import com.mysql.clusterj.SessionFactory;
import com.mysql.clusterj.Session;
import com.mysql.clusterj.Query;
import com.mysql.clusterj.query.QueryBuilder;
import com.mysql.clusterj.query.QueryDomainType;
import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.*;
import java.util.Properties;
import java.util.List;
public class Main {
public static void main (String[] args) throws java.io.FileNotFoundException,java.io.IOException {
// Load the properties from the clusterj.properties file
File propsFile = new File("clusterj.properties");
InputStream inStream = new FileInputStream(propsFile);
Properties props = new Properties();
props.load(inStream);
//Used later to get userinput
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
The next step is to get a handle for a SessionFactory from the ClusterJHelper class and then use that factory to create a session (based on the properties imported from clusterj.properties file.
Main.java (part 2):
// Create a session (connection to the database)
SessionFactory factory = ClusterJHelper.getSessionFactory(props);
Session session = factory.getSession();
Now that we have a session, it is possible to instantiate new Employee objects and then persist them to the database. Where there are no transaction begin() or commit() statements, each operation involving the database is treated as a separate transaction.
Main.java (part 3):
// Create and initialise an Employee
Employee newEmployee = session.newInstance(Employee.class);
newEmployee.setId(988);
newEmployee.setFirst("John");
newEmployee.setLast("Jones");
newEmployee.setStarted("1 February 2009");
newEmployee.setDepartment(666);
// Write the Employee to the database
session.persist(newEmployee);
At this point, a row will have been added to the ‘employee’ table. To verify this, a new Employee object is created and used to read the data back from the ‘employee’ table using the primary key (Id) value of 998:
Main.java (part 4):
// Fetch the Employee from the database
 Employee theEmployee = session.find(Employee.class, 988);
if (theEmployee == null)
 {System.out.println("Could not find employee");}
else
 {System.out.println ("ID: " + theEmployee.getId() + "; Name: " +
 theEmployee.getFirst() + " " + theEmployee.getLast());
 System.out.println ("Location: " + theEmployee.getCity());
 System.out.println ("Department: " + theEmployee.getDepartment());
 System.out.println ("Started: " + theEmployee.getStarted());
 System.out.println ("Left: " + theEmployee.getEnded());
}
This is the output seen at this point:
ID: 988; Name: John Jones
Location: null
Department: 666
Started: 1 February 2009
Left: null
Check the database before I change the Employee - hit return when you are done
The next step is to modify this data but it does not write it back to the database yet:
Main.java (part 5):
// Make some changes to the Employee &#38; write back to the database
theEmployee.setDepartment(777);
theEmployee.setCity("London");
System.out.println("Check the database before I change the Employee -
hit return when you are done");
String ignore = br.readLine();
The application will pause at this point and give you chance to check the database to confirm that the original data has been added as a new row but the changes have not been written back yet:
mysql&#62; select * from clusterdb.employee;
+-----+-------+-------+--------------+-----------------+-------+------------+
&#124; id  &#124; first &#124; last  &#124; municipality &#124; started         &#124; ended &#124; department &#124;
+-----+-------+-------+--------------+-----------------+-------+------------+
&#124; 988 &#124; John  &#124; Jones &#124; NULL         &#124; 1 February 2009 &#124; NULL  &#124;        666 &#124;
+-----+-------+-------+--------------+-----------------+-------+------------+
After hitting return, the application will continue and write the changes to the table, using an automatic transaction to perform the update.
Main.java (part 6):
session.updatePersistent(theEmployee);
System.out.println("Check the change in the table before I bulk add
Employees - hit return when you are done");
ignore = br.readLine();
The application will again pause so that we can now check that the change has been written back (persisted) to the database:
mysql&#62; select * from clusterdb.employee;
+-----+-------+-------+--------------+-----------------+-------+------------+
&#124; id  &#124; first &#124; last  &#124; municipality &#124; started         &#124; ended &#124; department &#124;
+-----+-------+-------+--------------+-----------------+-------+------------+
&#124; 988 &#124; John  &#124; Jones &#124; London       &#124; 1 February 2009 &#124; NULL  &#124;        777 &#124;
+-----+-------+-------+--------------+-----------------+-------+------------+
The application then goes onto create and persist 100 new employees. To improve performance, a single transaction is used to that all of the changes can be written to the database at once when the commit() statement is run:
Main.java (part 7):
// Add 100 new Employees - all as part of a single transaction
 newEmployee.setFirst("Billy");
 newEmployee.setStarted("28 February 2009");
session.currentTransaction().begin();
for (int i=700;i&#60;800;i++) {
 newEmployee.setLast("No-Mates"+i);
 newEmployee.setId(i+1000);
 newEmployee.setDepartment(i);
 session.persist(newEmployee);
 }
session.currentTransaction().commit();
The 100 new employees will now have been persisted to the database. The next step is to create and execute a query that will search the database for all employees in department 777 by using a QueryBuilder and using that to build a QueryDomain that compares the ‘department’ column with a parameter. After creating the, the department parameter is set to 777 (the query could subsequently be reused with different department numbers). The application then runs the query and iterates through and displays each of employees in the result set:
Main.java (part 8):
// Retrieve the set all of Employees in department 777
QueryBuilder builder = session.getQueryBuilder();
QueryDomainType&#60;Employee&#62; domain =
builder.createQueryDefinition(Employee.class);
domain.where(domain.get("department").equal(domain.param(
"department")));
Query&#60;Employee&#62; query = session.createQuery(domain);
query.setParameter("department",777);
List&#60;Employee&#62; results = query.getResultList();
for (Employee deptEmployee: results) {
System.out.println ("ID: " + deptEmployee.getId() + "; Name: " +
deptEmployee.getFirst() + " " + deptEmployee.getLast());
System.out.println ("Location: " + deptEmployee.getCity());
System.out.println ("Department: " + deptEmployee.getDepartment());
System.out.println ("Started: " + deptEmployee.getStarted());
System.out.println ("Left: " + deptEmployee.getEnded());
}
System.out.println("Last chance to check database before emptying table
- hit return when you are done");
ignore = br.readLine();
At this point, the application will display the following and prompt the user to allow it to continue:
ID: 988; Name: John Jones
Location: London
Department: 777
Started: 1 February 2009
Left: null
ID: 1777; Name: Billy No-Mates777
Location: null
Department: 777
Started: 28 February 2009
Left: null
We can compare that output with an SQL query performed on the database:
mysql&#62; select * from employee where department=777;
 +------+-------+-------------+--------------+------------------+-------+------------+
 &#124; id   &#124; first &#124; last        &#124; municipality &#124; started          &#124; ended &#124; department &#124;
 +------+-------+-------------+--------------+------------------+-------+------------+
 &#124;  988 &#124; John  &#124; Jones       &#124; London       &#124; 1 February 2009  &#124; NULL  &#124;        777 &#124;
 &#124; 1777 &#124; Billy &#124; No-Mates777 &#124; NULL         &#124; 28 February 2009 &#124; NULL  &#124;        777 &#124;
 +------+-------+-------------+--------------+------------------+-------+------------+
Finally, after pressing return again, the application will remove all employees:
Main.java (part 9):
session.deletePersistentAll(Employee.class);
 }
}
As a final check, an SQL query confirms that all of the rows have been deleted from the ‘employee’ table.
mysql&#62; select * from employee;
Empty set (0.00 sec)
Compiling and running the ClusterJ tutorial code
javac -classpath /usr/local/mysql/share/mysql/java/clusterj-api.jar:. Main.java Employee.java
java -classpath /usr/local/mysql/share/mysql/java/clusterj.jar:. -Djava.library.path=/usr/local/mysql/lib Main
 
Download the source code for this tutorial from here (together with the code for the up-coming ClusterJPA tutorial).]]></description>
			<content:encoded><![CDATA[<div><a href="http://www.clusterdb.com/wp-content/uploads/2010/03/ClusterJ_Stack.jpg"><img class="size-medium wp-image-1010" title="Java access to MySQL Cluster" src="http://www.clusterdb.com/wp-content/uploads/2010/03/ClusterJ_Stack-224x300.jpg" alt="" width="224" height="300" /></a><p>Fig. 1 Java access to MySQL Cluster</p></div>
<p>ClusterJ is part of the MySQL Cluster Connector for Java which is currently in beta as part of MySQL Cluster 7.1. It is designed to provide a high performance method for Java applications to store and access data in a MySQL Cluster database. It is also designed to be easy for Java developers to use and is “in the style of” Hibernate/Java Data Objects (JDO) and JPA. It uses the Domain Object Model DataMapper pattern:</p>
<ul>
<li>Data is represented as domain objects</li>
<li>Domain objects are separate from business logic</li>
<li>Domain objects are mapped to database tables</li>
</ul>
<p>The purpose of ClusterJ is to provide a mapping from the table-oriented view of the data stored in MySQL Cluster to the Java objects used by the application. This is achieved by annotating interfaces representing the Java objects; where each persistent interface is mapped to a table and each property in that interface to a column. By default, the table name will match the interface name and the column names match the property names but this can be overridden using annotations.</p>
<div><a href="http://www.clusterdb.com/wp-content/uploads/2010/03/ClusterJ_Annotations.jpg"><img class="size-medium wp-image-1011" title="ClusterJ_Annotations" src="http://www.clusterdb.com/wp-content/uploads/2010/03/ClusterJ_Annotations-300x159.jpg" alt="" width="300" height="159" /></a><p>Fig. 2 ClusterJ Interface Annotations</p></div>
<p>If the table does not already exist (for example, this is a brand new application with new data) then the table must be created manually &#8211; unlike OpenJPA, ClusterJ will not create the table automatically.</p>
<p>Figure 2 shows an example of an interface that has been created in order to represent the data held in the ‘employee’ table.</p>
<p>ClusterJ uses the following concepts:</p>
<ul>
<li>
<div><a href="http://www.clusterdb.com/wp-content/uploads/2010/03/ClusterJ_concepts.jpg"><img class="size-medium wp-image-1013" title="ClusterJ_concepts" src="http://www.clusterdb.com/wp-content/uploads/2010/03/ClusterJ_concepts-300x300.jpg" alt="" width="300" height="300" /></a><p>Fig. 3 ClusterJ Terminology</p></div>
<p><strong>SessionFactory</strong>: There is one instance per MySQL Cluster instance for each Java Virtual Machine (JVM). The SessionFactory object is used by the application to get hold of sessions. The configuration details for the ClusterJ instance are defined in the Configuration properties which is an artifact associated with the SessionFactory.</li>
<li><strong>Session</strong>: There is one instance per user (per Cluster, per JVM) and represents a Cluster connection</li>
<li><strong>Domain Object</strong>: Objects representing the data from a table. The domain objects (and their relationships to the Cluster tables) are defined by annotated interfaces (as shown in the right-hand side of Figure 2.</li>
<li><strong>Transaction</strong>: There is one transaction per session at any point in time. By default, each operation (query, insert, update, or delete) is run under a new transaction. . The Transaction interface allows developers to aggregate multiple operations into a single, atomic unit of work.</li>
</ul>
<p>ClusterJ will be suitable for many Java developers but it has some restrictions which may make OpenJPA with the ClusterJPA plug-in more appropriate. These ClusterJ restrictions are:</p>
<ul>
<li>Persistent Interfaces rather than persistent classes. The developer provides the signatures for the getter/setter methods rather than the properties and no extra methods can be added.</li>
<li>No Relationships between properties or between objects can be defined in the domain objects. Properties are primitive types.</li>
<li>No Multi-table inheritance; there is a single table per persistent interface</li>
<li>No joins in queries (all data being queried must be in the same table/interface)</li>
<li>No Table creation &#8211; user needs to create tables and indexes</li>
<li>No Lazy Loading &#8211; entire record is loaded at one time, including large object (LOBs).</li>
</ul>
<h3>Tutorial</h3>
<p>This tutorial uses MySQL Cluster 7.1.2a on Fedora 12. If using earlier or more recent versions of MySQL Cluster then you may need to change the class-paths as explained in <a href="http://dev.mysql.com/doc/ndbapi/en/mccj-using-clusterj.html" >http://dev.mysql.com/doc/ndbapi/en/mccj-using-clusterj.html</a></p>
<p>It is necessary to have MySQL Cluster up and running. For simplicity all of the nodes (processes) making up the Cluster will be run on the same physical host, along with the application.</p>
<p>These are the MySQL Cluster configuration files being used :</p>
<p><strong>config.ini:</strong></p>
<pre><span>[ndbd default]noofreplicas=2
datadir=/home/billy/mysql/my_cluster/data

[ndbd]
hostname=localhost
id=3

[ndbd]
hostname=localhost
id=4

[ndb_mgmd]
id = 1
hostname=localhost
datadir=/home/billy/mysql/my_cluster/data

[mysqld]
hostname=localhost
id=101

[api]
hostname=localhost</span></pre>
<p><strong>my.cnf:</strong></p>
<pre><span>[mysqld]
ndbcluster
datadir=/home/billy/mysql/my_cluster/data
basedir=/usr/local/mysql</span></pre>
<p>This tutorial focuses on ClusterJ rather than on running MySQL Cluster; if you are new to MySQL Cluster then refer to <a href="http://www.clusterdb.com/mysql-cluster/creating-a-simple-cluster-on-a-single-linux-host/" >running a simple Cluster</a> before trying this tutorial.</p>
<p>ClusterJ needs to be told how to connect to our MySQL Cluster database; including the connect string (the address/port for the management node), the database to use, the user to login as and attributes for the connection such as the timeout values. If these parameters aren’t defined then ClusterJ will fail with run-time exceptions. This information represents the “configuration properties” shown in Figure 3.  These parameters can be hard coded in the application code but it is more maintainable to create a clusterj.properties file that will be imported by the application. This file should be stored in the same directory as your application source code.</p>
<p><strong>clusterj.properties:</strong></p>
<pre><span>com.mysql.clusterj.connectstring=localhost:1186
 com.mysql.clusterj.database=clusterdb
 com.mysql.clusterj.connect.retries=4
 com.mysql.clusterj.connect.delay=5
 com.mysql.clusterj.connect.verbose=1
 com.mysql.clusterj.connect.timeout.before=30
 com.mysql.clusterj.connect.timeout.after=20
 com.mysql.clusterj.max.transactions=1024
 com.mysql.clusterj.username=
 com.mysql.clusterj.password=</span></pre>
<p>As ClusterJ will not create tables automatically, the next step is to create ‘clusterdb’ database (referred to in clusterj.properties) and the ‘employee’ table:</p>
<pre><span>[billy@ws1 ~]$ mysql -u root -h 127.0.0.1 -P 3306 -u root
 mysql&gt;  create database clusterdb;use clusterdb;
 mysql&gt; CREATE TABLE employee (
 -&gt;     id INT NOT NULL PRIMARY KEY,
 -&gt;     first VARCHAR(64) DEFAULT NULL,
 -&gt;     last VARCHAR(64) DEFAULT NULL,
 -&gt;     municipality VARCHAR(64) DEFAULT NULL,
 -&gt;     started VARCHAR(64) DEFAULT NULL,
 -&gt;     ended  VARCHAR(64) DEFAULT NULL,
 -&gt;     department INT NOT NULL DEFAULT 1,
 -&gt;     UNIQUE KEY idx_u_hash (first,last) USING HASH,
 -&gt;     KEY idx_municipality (municipality)
 -&gt; ) ENGINE=NDBCLUSTER;</span></pre>
<p>The next step is to create the annotated interface:</p>
<p><strong>Employee.java:</strong></p>
<pre><span>import com.mysql.clusterj.annotation.Column;
import com.mysql.clusterj.annotation.Index;
import com.mysql.clusterj.annotation.PersistenceCapable;
import com.mysql.clusterj.annotation.PrimaryKey;</span></pre>
<pre><span>@PersistenceCapable(table="employee")
@Index(name="idx_uhash")
public interface Employee {</span></pre>
<pre><span>@PrimaryKey
int getId();
void setId(int id);</span></pre>
<pre><span>String getFirst();
void setFirst(String first);

String getLast();
void setLast(String last);</span></pre>
<pre><span>@Column(name="municipality")
@Index(name="idx_municipality")
String getCity();
void setCity(String city);</span></pre>
<pre><span>String getStarted();
void setStarted(String date);</span></pre>
<pre><span>String getEnded();
void setEnded(String date);</span></pre>
<pre><span>Integer getDepartment();
void setDepartment(Integer department);
}</span></pre>
<p>The name of the table is specified in the annotation @PersistenceCapable(table=&#8221;employee&#8221;) and then each column from the employee table has an associated getter and setter method defined in the interface. By default, the property name in the interface is the same as the column name in the table – the column name has been overridden for the City property by explicitly including the @Column(name=&#8221;municipality&#8221;) annotation just before the associated getter method. The @PrimaryKey annotation is used to identify the property whose associated column is the Primary Key in the table. ClusterJ is made aware of the existence of indexes in the database using the @Index annotation.</p>
<p>The next step is to write the application code which we step through here block by block; the first of which simply contains the import statements and then loads the contents of the clusterj.properties defined above (Note – refer to section 3.2.1 for details on compiling and running the tutorial code):</p>
<p><strong>Main.java (part 1):</strong></p>
<pre><span>import com.mysql.clusterj.ClusterJHelper;
import com.mysql.clusterj.SessionFactory;
import com.mysql.clusterj.Session;
import com.mysql.clusterj.Query;
import com.mysql.clusterj.query.QueryBuilder;
import com.mysql.clusterj.query.QueryDomainType;</span></pre>
<pre><span>import java.io.File;
import java.io.InputStream;
import java.io.FileInputStream;
import java.io.*;</span></pre>
<pre><span>import java.util.Properties;
import java.util.List;</span></pre>
<pre><span>public class Main {</span></pre>
<pre><span>public static void main (String[] args) throws java.io.FileNotFoundException,java.io.IOException {</span></pre>
<pre><span>// Load the properties from the clusterj.properties file</span></pre>
<pre><span>File propsFile = new File("clusterj.properties");
InputStream inStream = new FileInputStream(propsFile);
Properties props = new Properties();
props.load(inStream);</span></pre>
<pre><span>//Used later to get userinput
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));</span></pre>
<p>The next step is to get a handle for a SessionFactory from the ClusterJHelper class and then use that factory to create a session (based on the properties imported from clusterj.properties file.</p>
<p><strong>Main.java (part 2):</strong></p>
<pre><span>// Create a session (connection to the database)
SessionFactory factory = ClusterJHelper.getSessionFactory(props);
Session session = factory.getSession();</span></pre>
<p>Now that we have a session, it is possible to instantiate new Employee objects and then persist them to the database. Where there are no transaction begin() or commit() statements, each operation involving the database is treated as a separate transaction.</p>
<p><strong>Main.java (part 3):</strong></p>
<pre><span>// Create and initialise an Employee
Employee newEmployee = session.newInstance(Employee.class);
newEmployee.setId(988);
newEmployee.setFirst("John");
newEmployee.setLast("Jones");
newEmployee.setStarted("1 February 2009");
newEmployee.setDepartment(666);</span></pre>
<pre><span>// Write the Employee to the database
session.persist(newEmployee);</span></pre>
<p>At this point, a row will have been added to the ‘employee’ table. To verify this, a new Employee object is created and used to read the data back from the ‘employee’ table using the primary key (Id) value of 998:</p>
<p><strong>Main.java (part 4):</strong></p>
<pre><span>// Fetch the Employee from the database
 Employee theEmployee = session.find(Employee.class, 988);</span></pre>
<pre><span>if (theEmployee == null)
 {System.out.println("Could not find employee");}
else
 {System.out.println ("ID: " + theEmployee.getId() + "; Name: " +
 theEmployee.getFirst() + " " + theEmployee.getLast());
 System.out.println ("Location: " + theEmployee.getCity());
 System.out.println ("Department: " + theEmployee.getDepartment());
 System.out.println ("Started: " + theEmployee.getStarted());
 System.out.println ("Left: " + theEmployee.getEnded());
}</span></pre>
<p>This is the output seen at this point:</p>
<pre><span>ID: 988; Name: John Jones
Location: null
Department: 666
Started: 1 February 2009
Left: null
Check the database before I change the Employee - hit return when you are done</span></pre>
<p>The next step is to modify this data but it does not write it back to the database yet:</p>
<p><strong>Main.java (part 5):</strong></p>
<pre><span>// Make some changes to the Employee &amp; write back to the database
theEmployee.setDepartment(777);
theEmployee.setCity("London");</span></pre>
<pre><span>System.out.println("Check the database before I change the Employee -
hit return when you are done");
String ignore = br.readLine();</span></pre>
<p>The application will pause at this point and give you chance to check the database to confirm that the original data has been added as a new row but the changes have not been written back yet:</p>
<pre><span>mysql&gt; select * from clusterdb.employee;
+-----+-------+-------+--------------+-----------------+-------+------------+
| id  | first | last  | municipality | started         | ended | department |
+-----+-------+-------+--------------+-----------------+-------+------------+
| 988 | John  | Jones | NULL         | 1 February 2009 | NULL  |        666 |
+-----+-------+-------+--------------+-----------------+-------+------------+</span></pre>
<p>After hitting return, the application will continue and write the changes to the table, using an automatic transaction to perform the update.</p>
<p><strong>Main.java (part 6):</strong></p>
<pre><span>session.updatePersistent(theEmployee);</span></pre>
<pre><span>System.out.println("Check the change in the table before I bulk add
Employees - hit return when you are done");
ignore = br.readLine();</span></pre>
<p>The application will again pause so that we can now check that the change has been written back (persisted) to the database:</p>
<pre><span>mysql&gt; select * from clusterdb.employee;
+-----+-------+-------+--------------+-----------------+-------+------------+
| id  | first | last  | municipality | started         | ended | department |
+-----+-------+-------+--------------+-----------------+-------+------------+
| 988 | John  | Jones | London       | 1 February 2009 | NULL  |        777 |
+-----+-------+-------+--------------+-----------------+-------+------------+</span></pre>
<p>The application then goes onto create and persist 100 new employees. To improve performance, a single transaction is used to that all of the changes can be written to the database at once when the commit() statement is run:</p>
<p><strong>Main.java (part 7):</strong></p>
<pre><span>// Add 100 new Employees - all as part of a single transaction
 newEmployee.setFirst("Billy");
 newEmployee.setStarted("28 February 2009");</span></pre>
<pre><span>session.currentTransaction().begin();</span></pre>
<pre><span>for (int i=700;i&lt;800;i++) {
 newEmployee.setLast("No-Mates"+i);
 newEmployee.setId(i+1000);
 newEmployee.setDepartment(i);
 session.persist(newEmployee);
 }</span></pre>
<pre><span>session.currentTransaction().commit();</span></pre>
<p>The 100 new employees will now have been persisted to the database. The next step is to create and execute a query that will search the database for all employees in department 777 by using a QueryBuilder and using that to build a QueryDomain that compares the ‘department’ column with a parameter. After creating the, the department parameter is set to 777 (the query could subsequently be reused with different department numbers). The application then runs the query and iterates through and displays each of employees in the result set:</p>
<p><strong>Main.java (part 8):</strong></p>
<pre><span>// Retrieve the set all of Employees in department 777
QueryBuilder builder = session.getQueryBuilder();
QueryDomainType&lt;Employee&gt; domain =
builder.createQueryDefinition(Employee.class);
domain.where(domain.get("department").equal(domain.param(
"department")));
Query&lt;Employee&gt; query = session.createQuery(domain);
query.setParameter("department",777);</span></pre>
<pre><span>List&lt;Employee&gt; results = query.getResultList();
for (Employee deptEmployee: results) {
System.out.println ("ID: " + deptEmployee.getId() + "; Name: " +
deptEmployee.getFirst() + " " + deptEmployee.getLast());
System.out.println ("Location: " + deptEmployee.getCity());
System.out.println ("Department: " + deptEmployee.getDepartment());
System.out.println ("Started: " + deptEmployee.getStarted());
System.out.println ("Left: " + deptEmployee.getEnded());
}</span></pre>
<pre><span>System.out.println("Last chance to check database before emptying table
- hit return when you are done");
ignore = br.readLine();</span></pre>
<p>At this point, the application will display the following and prompt the user to allow it to continue:</p>
<pre><span>ID: 988; Name: John Jones
Location: London
Department: 777
Started: 1 February 2009
Left: null
ID: 1777; Name: Billy No-Mates777
Location: null
Department: 777
Started: 28 February 2009
Left: null</span></pre>
<p>We can compare that output with an SQL query performed on the database:</p>
<pre><span>mysql&gt; select * from employee where department=777;
 +------+-------+-------------+--------------+------------------+-------+------------+
 | id   | first | last        | municipality | started          | ended | department |
 +------+-------+-------------+--------------+------------------+-------+------------+
 |  988 | John  | Jones       | London       | 1 February 2009  | NULL  |        777 |
 | 1777 | Billy | No-Mates777 | NULL         | 28 February 2009 | NULL  |        777 |
 +------+-------+-------------+--------------+------------------+-------+------------+</span></pre>
<p>Finally, after pressing return again, the application will remove all employees:</p>
<p><strong>Main.java (part 9):</strong></p>
<pre><span>session.deletePersistentAll(Employee.class);
 }
}</span></pre>
<p>As a final check, an SQL query confirms that all of the rows have been deleted from the ‘employee’ table.</p>
<pre><span>mysql&gt; select * from employee;
Empty set (0.00 sec)</span></pre>
<h4>Compiling and running the ClusterJ tutorial code</h4>
<pre><span>javac -classpath /usr/local/mysql/share/mysql/java/clusterj-api.jar:. Main.java Employee.java</span></pre>
<pre><span>java -classpath /usr/local/mysql/share/mysql/java/clusterj.jar:. -Djava.library.path=/usr/local/mysql/lib Main
</span><span> </span></pre>
<p><a href="http://www.clusterdb.com/ClusterJ_Examples.tar.gz" >Download the source code for this tutorial from here </a>(together with the code for the up-coming ClusterJPA tutorial).</p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24094&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=24094&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/03/30/using-clusterj-part-of-mysql-cluster-connector-for-java-%e2%80%93-a-tutorial/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Build MySQL Cluster 7.1 from source – including MySQL Cluster Connector for Java</title>
		<link>http://www.clusterdb.com/mysql-cluster/build-mysql-cluster-7-1-from-source-including-mysql-cluster-connector-for-java/?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=build-mysql-cluster-7-1-from-source-%25e2%2580%2593-including-mysql-cluster-connector-for-java</link>
		<comments>http://www.clusterdb.com/mysql-cluster/build-mysql-cluster-7-1-from-source-including-mysql-cluster-connector-for-java/#comments</comments>
		<pubDate>Fri, 19 Mar 2010 12:09:57 +0000</pubDate>
		<dc:creator>Andrew Morgan</dc:creator>
				<category><![CDATA[ClusterJ]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[MySQL Cluster]]></category>
		<category><![CDATA[MySQL Cluster 7.1]]></category>
		<category><![CDATA[OpenJPA]]></category>

		<guid isPermaLink="false">http://www.clusterdb.com/?p=997</guid>
		<description><![CDATA[If you want to try out the beta features in MySQL Cluster 7.1 then you can either use the appropriate binaries or you can build it for yourself from source. Here I explain how to do this on LINUX.
Note that if you want to make use of OpenJPA then you first need to install OpenJPA and Connector/J.
The example here was on Fedora12 with the MySQL Cluster 7.1.2 source:
CFLAGS=&#8221;-O3&#8243; CXX=gcc CXXFLAGS=&#8221;-O3 -felide-constructors -fno-exceptions -fno-rtti&#8221; ./configure -prefix=/usr/local/mysql &#8211;enable-assembler &#8211;with-mysqld-ldflags=-all-static &#8211;with-plugins=max &#8211;with-openjpa &#8211;with-classpath=/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/geronimo-jpa_3.0_spec-1.0.jar:/usr/local/openjpa/lib/geronimo-jta_1.1_spec-1.1.jar  &#8211;with-extra-charsets=all
make
make install
That&#8217;s it! Obviously, the exact location of the OpenJPA jars will depend on where you installed it. Note that for &#8216;make install&#8217; you need to run it from an account that has access to /usr/local
I&#8217;ll follow up a little later with a post with example applications (in the mean time refer to this tutorial or the MySQL Cluster for Java on-line documentation) but FYI these are the options I use to compile and run my test aps:
ClusterJ:
javac -classpath /usr/local/mysql/share/mysql/java/clusterj-api.jar:. Main.java Employee.java
java -classpath /usr/local/mysql/share/mysql/java/clusterj.jar:. -Djava.library.path=/usr/local/mysql/lib/mysql/ Main


ClusterJPA:
javac -classpath /usr/local/mysql/share/mysql/java/clusterjpa.jar:/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/geronimo-jpa_3.0_spec-1.0.jar:. Main.java Employee.java Department.java
java -Djava.library.path=/usr/local/mysql/lib/mysql/ -classpath /usr/local/mysql/share/mysql/java/clusterjpa.jar:/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/*:/usr/local/connectorj/mysql-connector-java-5.1.12-bin.jar:. Main]]></description>
			<content:encoded><![CDATA[<p>If you want to try out the beta features in MySQL Cluster 7.1 then you can either use the appropriate binaries or you can build it for yourself from source. Here I explain how to do this on LINUX.</p>
<p>Note that if you want to make use of OpenJPA then you first need to install <a href="http://openjpa.apache.org/" >OpenJPA</a> and <a href="http://dev.mysql.com/downloads/connector/j/" >Connector/J</a>.</p>
<p>The example here was on Fedora12 with the <a href="http://dev.mysql.com/downloads/cluster/#downloads" >MySQL Cluster 7.1.2 source</a>:</p>
<blockquote><p><span>CFLAGS=&#8221;-O3&#8243; CXX=gcc CXXFLAGS=&#8221;-O3 -felide-constructors -fno-exceptions -fno-rtti&#8221; ./configure -prefix=/usr/local/mysql &#8211;enable-assembler &#8211;with-mysqld-ldflags=-all-static &#8211;with-plugins=max &#8211;with-openjpa &#8211;with-classpath=/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/geronimo-jpa_3.0_spec-1.0.jar:/usr/local/openjpa/lib/geronimo-jta_1.1_spec-1.1.jar  &#8211;with-extra-charsets=all</span></p>
<p><span>make</span></p>
<p><span>make install</span></p></blockquote>
<p>That&#8217;s it! Obviously, the exact location of the OpenJPA jars will depend on where you installed it. Note that for &#8216;make install&#8217; you need to run it from an account that has access to /usr/local</p>
<p>I&#8217;ll follow up a little later with a post with example applications (in the mean time refer to this <a href="http://ocklin.blogspot.com/2009/12/java-and-openjpa-for-mysql-cluster_14.html" >tutorial</a> or the <a href="http://dev.mysql.com/doc/ndbapi/en/mccj.html" >MySQL Cluster for Java on-line documentation</a>) but FYI these are the options I use to compile and run my test aps:</p>
<blockquote><p><span><strong>ClusterJ</strong>:</span></p>
<p><span>javac -classpath /usr/local/mysql/share/mysql/java/clusterj-api.jar:. Main.java Employee.java</span></p>
<p><span>java -classpath /usr/local/mysql/share/mysql/java/clusterj.jar:. -Djava.library.path=/usr/local/mysql/lib/mysql/ Main</span></p>
<p><span><br />
</span></p>
<p><span><strong>ClusterJPA</strong>:</span></p>
<p><span>javac -classpath /usr/local/mysql/share/mysql/java/clusterjpa.jar:/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/geronimo-jpa_3.0_spec-1.0.jar:. Main.java Employee.java Department.java</span></p>
<p><span>java -Djava.library.path=/usr/local/mysql/lib/mysql/ -classpath /usr/local/mysql/share/mysql/java/clusterjpa.jar:/usr/local/openjpa/openjpa-1.2.1.jar:/usr/local/openjpa/lib/*:/usr/local/connectorj/mysql-connector-java-5.1.12-bin.jar:. Main</span></p></blockquote><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23957&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=23957&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2010/03/19/build-mysql-cluster-7-1-from-source-%e2%80%93-including-mysql-cluster-connector-for-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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 #99: Creating a Java EE 6 application using MySQL, JPA 2.0 and Servlet 3.0 with GlassFish Tools Bundle for Eclipse</title>
		<link>http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java?utm_source=rss&#038;utm_medium=rss&#038;utm_campaign=totd-99-creating-a-java-ee-6-application-using-mysql-jpa-2-0-and-servlet-3-0-with-glassfish-tools-bundle-for-eclipse</link>
		<comments>http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java#comments</comments>
		<pubDate>Mon, 31 Aug 2009 12:00:00 +0000</pubDate>
		<dc:creator>Arun Gupta</dc:creator>
				<category><![CDATA[database]]></category>
		<category><![CDATA[eclipse]]></category>
		<category><![CDATA[General]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[jpa]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://blogs.sun.com/arungupta/entry/totd_99_creating_a_java</guid>
		<description><![CDATA[TOTD #97 showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options - either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.
TOTD #98 showed how to create a simple Metro/JAX-WS compliant Web service using that bundle and deploy on GlassFish. 
This Tip Of The Day (TOTD) shows how to create a simple Java EE 6 application that reads data from a MySQL database using JPA 2.0 and Servlet 3.0 and display the results. A more formal support of Java EE 6/Servlet 3.0 is coming but in the meanwhile the approach mentioned below will work.
Lets get started!

    
Configure database connection - The key point to notice here is that the MySQL Connector/J driver is already built into the tool so there is no need to configure it explicitly.
        
            From &#34;Window&#34;, &#34;Show Perspective&#34;, change to the database perspective as shown below:
            In the &#34;Data Source Explorer&#34;, right-click and click on &#34;Database Connections&#34; and select &#34;New ...&#34;:
            Search for &#34;mysql&#34; and type the database name as &#34;sakila&#34;:This blog uses MySQL sample database sakila. So please download and install the sample database before proceeding further.
            Click on &#34;Next &#62;&#34; and specify the database configuration:Notice the &#34;Drivers&#34; indicate that the JDBC driver is pre-bundled so there is no extra configuration required. If you are using a stand-alone Eclipse bunde and installing the plugin separately, then you need to configure the MySQL JDBC driver explictily.The URL indicates the application is connecting to the sakila database. Click on &#34;Test Connection&#34; to test connection with the database and see the output as:and click on &#34;Finish&#34; to complete. The expanded database in the explorer looks like:The expanded view shows all the tables in the database.
        
    
    
Create the Web project &#38; configure JPA
        
            Switch to JavaEE perspective by clicking &#34;Window&#34;, &#34;Choose Perspective&#34;, &#34;Other ...&#34; and choosing &#34;Java EE&#34;.
            Create a new dynamic web project with the following settings:Only the project name needs to be specified and everything else is default. Notice the target runtime indicates that this is a Java EE 6 application. Click on &#34;Finish&#34;.
            Right-click on the project, search for &#34;facets&#34; and enable &#34;Java Persistence&#34; as shown below:
            Click on &#34;Further configuration available ...&#34; and modify the facet as shown below:Make sure to disable &#34;orm.xml&#34; since we are generating a standard Java EE 6 web application. Choose &#34;sakila&#34; as the database. Click on &#34;OK&#34; and again on &#34;OK&#34; to complete the dialog.
        
    
    
Generate the JPA entities
        
            Right-click on the project, select &#34;JPA Tools&#34;, &#34;Generate Entities&#34; as shown:
            Choose the schema &#34;sakila&#34;:and click on &#34;Next &#62;&#34;. If no values are shown in the schema drop-down, then click on &#34;Reconnect ...&#34;.
            Specify a package name for the generated entities as &#34;model&#34; and select &#34;film&#34; and &#34;language&#34; table:and click on &#34;Finish&#34;. The &#34;film&#34; and &#34;language&#34; table are related so it would be nice if all the related tables can be identified and picked accordingly.Anyway this generates &#34;model.Film&#34; and &#34;model.Language&#34; classes and &#34;persistence.xml&#34; as shown below:Also notice that &#34;web.xml&#34; and &#34;sun-web.xml&#34; have been explicitly removed since they are not required by a Java EE 6 application.
            &#34;model.Film&#34; class needs to modified slightly because one of the columns is mapped to &#34;Object&#34; which is not a Serializable obect. So change the type of &#34;specialFeatures&#34; from Object to String and also change the corresponding getters/setters accordingly. The error message clearly conveyed during the initial deployment and so could be fixed. But it would be nice to generate the classes that will work out-of-the-box.
        
    
    
Create a Servlet client to retrieve/display data from the database
        
            Right-click on the project, select &#34;New&#34;, &#34;Class&#34; and specify the values as:and click on &#34;Finish&#34;. This class will be our Servlet client.
            
Change the class such that it looks like:                
@WebServlet(urlPatterns="/ServletClient")
public class ServletClient extends HttpServlet {
  @PersistenceUnit
  EntityManagerFactory factory;

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream();
    List list = factory.createEntityManager().createQuery("select f from Film f where f.title like 'GL%';").getResultList();
    out.println("&#60;html&#62;&#60;table&#62;");
    for (Object film : list) {
      out.print("&#60;tr&#62;&#60;td&#62;" + ((Film)film).getTitle() + "&#60;/tr&#62;&#60;/td&#62;");
    }
    out.println("&#60;/table&#62;&#60;/html&#62;");
  }
}

and the imports as:                
import java.io.IOException;
import java.util.List;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Film;


Basically, this is a Servlet 3.0 specification compliant Servlet that uses @WebServlet annotation. It uses @PersistenceUnit to inject the generated JPA Persistence Unit which is then used to query the database. The database query return all the movies whose title start with &#34;GL&#34; and the response is displayed in an HTML formatted table.            
            Right-click on the project and select &#34;Run As&#34;, &#34;Run on Server&#34; and select GlassFish v3 latest promoted build (this blog used build 61) as: and click on &#34;Finish&#34;. The output at &#34;http://localhost:8080/HelloJPA/ServletClient&#34; looks like:
        
    

Simple, easy and clean!
How are you using Eclipse and GlassFish - the consolidated bundle or standalone Eclipse + GlassFish plugin ?
Download GlassFish Tools Bundle for Eclipse now.
Technorati: glassfish eclipse mysql jpa database
]]></description>
			<content:encoded><![CDATA[<a href="http://blog.arungupta.me/2009/08/totd-97-glassfish-plugin-with-eclipse-3-5/">TOTD #97</a> showed how to install GlassFish Tools Bundle for Eclipse 1.1. Basically there are two options - either install Eclipse 3.4.2 with WTP and pre-bundled/configured with GlassFish v2/v3, MySQL JDBC driver and other features. Or if you are using Eclipse 3.5, then you can install the plug-in separately and get most of the functionality.
<p><a href="http://blog.arungupta.me/2009/08/totd-98-create-a-metro-jax-ws-web-service-using-glassfish-tools-bundle-for-eclipse/">TOTD #98</a> showed how to create a simple <a href="http://metro.dev.java.net">Metro</a>/<a href="http://jax-ws.dev.java.net">JAX-WS</a> compliant Web service using that bundle and deploy on <a href="http://glassfish.org">GlassFish</a>. </p>
<p>This <strong>T</strong>ip <strong>O</strong>f <strong>T</strong>he <strong>D</strong>ay (TOTD) shows how to create a simple Java EE 6 application that reads data from a MySQL database using JPA 2.0 and Servlet 3.0 and display the results. A more formal support of Java EE 6/Servlet 3.0 is coming but in the meanwhile the approach mentioned below will work.</p>
<p>Lets get started!</p>
<ol>
    <li>
Configure database connection - The key point to notice here is that the <a href="http://www.mysql.com/products/connector/">MySQL Connector/J driver</a> is already built into the tool so there is no need to configure it explicitly.
        <ol>
            <li>From &quot;Window&quot;, &quot;Show Perspective&quot;, change to the database perspective as shown below:<br /><br /><img height="431" border="1" style="margin: 5px" width="360" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-choose-db-perspective1.png" /></li>
            <li>In the &quot;Data Source Explorer&quot;, right-click and click on &quot;Database Connections&quot; and select &quot;New ...&quot;:<br /><br /><img height="204" border="1" style="margin: 5px" width="302" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-new-db-connection1.png" /></li>
            <li>Search for &quot;mysql&quot; and type the database name as &quot;sakila&quot;:<br /><br /><img height="534" border="1" style="margin: 5px" width="523" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-search-mysql1.png" /><br /><br />This blog uses <a href="http://forge.mysql.com/wiki/SakilaSampleDB">MySQL sample database sakila</a>. So please <a href="http://downloads.mysql.com/docs/sakila-db.zip">download</a> and <a href="http://dev.mysql.com/doc/sakila/en/sakila.html#sakila-installation">install</a> the sample database before proceeding further.</li>
            <li>Click on &quot;Next &gt;&quot; and specify the database configuration:<br /><br /><img height="554" border="1" style="margin: 5px" width="522" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-sakila-configuration1.png" /><br /><br />Notice the &quot;Drivers&quot; indicate that the JDBC driver is pre-bundled so there is no extra configuration required. If you are using a stand-alone Eclipse bunde and installing the plugin separately, then you need to configure the MySQL JDBC driver explictily.<br /><br />The URL indicates the application is connecting to the sakila database. Click on &quot;Test Connection&quot; to test connection with the database and see the output as:<br /><br /><img height="259" border="1" style="margin: 5px" width="520" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-sakila-test-connection-output1.png" /><br /><br />and click on &quot;Finish&quot; to complete. The expanded database in the explorer looks like:<br /><br /><img height="707" border="1" style="margin: 5px" width="330" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-sakila-explorer-view1.png" /><br /><br />The expanded view shows all the tables in the database.</li>
        </ol>
    </li>
    <li>
Create the Web project &amp; configure JPA
        <ol>
            <li>Switch to JavaEE perspective by clicking &quot;Window&quot;, &quot;Choose Perspective&quot;, &quot;Other ...&quot; and choosing &quot;Java EE&quot;.</li>
            <li>Create a new dynamic web project with the following settings:<br /><br /><img height="549" border="1" style="margin: 5px" width="584" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-project-creation1.png" /><br /><br />Only the project name needs to be specified and everything else is default. Notice the target runtime indicates that this is a Java EE 6 application. Click on &quot;Finish&quot;.</li>
            <li>Right-click on the project, search for &quot;facets&quot; and enable &quot;Java Persistence&quot; as shown below:<br /><br /><img height="498" border="1" style="margin: 5px" width="646" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-persistence-facet1.png" /></li>
            <li>Click on &quot;Further configuration available ...&quot; and modify the facet as shown below:<br /><br /><img height="541" border="1" style="margin: 5px" width="518" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-jpa-configuration1.png" /><br /><br />Make sure to disable &quot;orm.xml&quot; since we are generating a standard Java EE 6 web application. Choose &quot;sakila&quot; as the database. Click on &quot;OK&quot; and again on &quot;OK&quot; to complete the dialog.</li>
        </ol>
    </li>
    <li>
Generate the JPA entities
        <ol>
            <li>Right-click on the project, select &quot;JPA Tools&quot;, &quot;Generate Entities&quot; as shown:<br /><br /><img height="161" border="1" style="margin: 5px" width="456" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-generate-entities1.png" /></li>
            <li>Choose the schema &quot;sakila&quot;:<br /><br /><img height="206" border="1" style="margin: 5px" width="354" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-generate-entities-db-connection1.png" /><br /><br />and click on &quot;Next &gt;&quot;. If no values are shown in the schema drop-down, then click on &quot;Reconnect ...&quot;.</li>
            <li>Specify a package name for the generated entities as &quot;model&quot; and select &quot;film&quot; and &quot;language&quot; table:<br /><br /><img height="614" border="1" style="margin: 5px" width="629" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-generate-entities-from-table1.png" /><br /><br />and click on &quot;Finish&quot;. The &quot;film&quot; and &quot;language&quot; table are related so it would be nice if all the related tables can be identified and picked accordingly.<br /><br />Anyway this generates &quot;model.Film&quot; and &quot;model.Language&quot; classes and &quot;persistence.xml&quot; as shown below:<br /><br /><img height="348" border="1" style="margin: 5px" width="242" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-entities-generated1.png" /><br /><br />Also notice that &quot;web.xml&quot; and &quot;sun-web.xml&quot; have been explicitly removed since they are not required by a Java EE 6 application.</li>
            <li>&quot;model.Film&quot; class needs to modified slightly because one of the columns is mapped to &quot;Object&quot; which is not a Serializable obect. So change the type of &quot;specialFeatures&quot; from Object to String and also change the corresponding getters/setters accordingly. The error message clearly conveyed during the initial deployment and so could be fixed. But it would be nice to generate the classes that will work out-of-the-box.</li>
        </ol>
    </li>
    <li>
Create a Servlet client to retrieve/display data from the database
        <ol>
            <li>Right-click on the project, select &quot;New&quot;, &quot;Class&quot; and specify the values as:<br /><br /><img height="575" border="1" style="margin: 5px" width="524" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-servlet-client1.png" /><br /><br />and click on &quot;Finish&quot;. This class will be our Servlet client.</li>
            <li>
Change the class such that it looks like:<br />                <pre>
@WebServlet(urlPatterns="/ServletClient")
public class ServletClient extends HttpServlet {
  @PersistenceUnit
  EntityManagerFactory factory;

  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
         throws ServletException, IOException {
    ServletOutputStream out = resp.getOutputStream();
    List list = factory.createEntityManager().createQuery("select f from Film f where f.title like 'GL%';").getResultList();
    out.println("&lt;html&gt;&lt;table&gt;");
    for (Object film : list) {
      out.print("&lt;tr&gt;&lt;td&gt;" + ((Film)film).getTitle() + "&lt;/tr&gt;&lt;/td&gt;");
    }
    out.println("&lt;/table&gt;&lt;/html&gt;");
  }
}
</pre>
<br />and the imports as:<br />                <pre>
import java.io.IOException;
import java.util.List;

import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceUnit;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.Film;

</pre>
Basically, this is a Servlet 3.0 specification compliant Servlet that uses @WebServlet annotation. It uses @PersistenceUnit to inject the generated JPA Persistence Unit which is then used to query the database. The database query return all the movies whose title start with &quot;GL&quot; and the response is displayed in an HTML formatted table.            </li>
            <li>Right-click on the project and select &quot;Run As&quot;, &quot;Run on Server&quot; and select <a href="http://download.java.net/glassfish/v3/promoted/">GlassFish v3 latest promoted build</a> (this blog used <a href="http://download.java.net/glassfish/v3/promoted/glassfish-v3-preview-b61.zip">build 61</a>) as:<br /><br /><img height="515" border="1" style="margin: 5px" width="506" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-run-on-server1.png" /><br /><br /> and click on &quot;Finish&quot;. The output at &quot;http://localhost:8080/HelloJPA/ServletClient&quot; looks like:<br /><br /><img height="186" border="1" style="margin: 5px" width="393" alt="" src="http://blog.arungupta.me/wp-content/uploads/2009/08/gftbe11-hellojpa-output-final.png" /></li>
        </ol>
    </li>
</ol>
<p>Simple, easy and clean!</p>
<p>How are you using Eclipse and GlassFish - the consolidated bundle or standalone Eclipse + GlassFish plugin ?</p>
<p>Download <a href="http://download.java.net/glassfish/eclipse/">GlassFish Tools Bundle for Eclipse</a> now.</p>
<p><small>Technorati: <a href="http://technorati.com/tags/glassfish">glassfish</a> <a href="http://technorati.com/tags/eclipse">eclipse</a> <a href="http://technorati.com/tags/mysql">mysql</a> <a href="http://technorati.com/tags/jpa">jpa</a> <a href="http://technorati.com/tags/database">database</a></small></p>
<p></p><br/>PlanetMySQL Voting:
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20870&vote=1&apivote=1">Vote UP</a> /
	 <a href="http://planet.mysql.com/entry/vote/?entry_id=20870&vote=-1&apivote=1">Vote DOWN</a>]]></content:encoded>
			<wfw:commentRss>http://planetmysql.ru/2009/08/31/totd-99-creating-a-java-ee-6-application-using-mysql-jpa-2-0-and-servlet-3-0-with-glassfish-tools-bundle-for-eclipse/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

