Miles to go …

March 11, 2010

DevNexus 2010 Trip Report

Filed under: eclipse, glassfish, javaee, netbeans — arungupta @ 9:20 pm
As mentioned earlier, I presented on Java E 6 & GlassFish v3 at DevNexus earlier this week. This is an annual conference by Atlanta Java Users Group and had three parallel tracks.

The conference was a sold out and the attendees packed Cobb Galleria conference rooms on both the days.

Anyway, the slides from my session are available below:

The speaking slots were bigger than normal, 70 minutes as opposed to normally 45 or 50 minutes. So that allowed to spend more time on the demos and show all the simplicity and ease-of-use with Java EE 6.  Optional "web.xml" is particularly well appreciated :-) And the attendees were hopeful that other vendors will start supporting Java EE 6 soon. For the record – Caucho, Geronimo, JBoss, and WebLogic have announced plans to be Java EE 6 compliant.

If you are interested in learning about Java EE (and several other topics), then GCA.net offers several of them all over the country. You can even avail a 10% on any class by registering at gca.net/devnexus. And if you are interested in specific learning paths on Java EE 6, then Oracle University has well designed courses.

Personally, I got to meet Dan Allen, Burr Sutter, James Ward, Venkat Subramaniam and many others. Burr is always an energetic personality and was live tweeting photographs of all the speakers. I loved his opening statement that DevNexus is about people who do what needs to be done, not who thinks what needs to be done. Basically he was joking on differences between "architects" and "developers" ;-) I also had some brief discussions with Dan on how Java EE adoption is important for the enterprise. His presentation on Contexts & Dependency Injection explained the concepts in simple manner. HIs slides should be soon available on Seam Wiki. Venkat’s keynote on Tuesday morning on "Facts and Fallacies of Software Development" was quite animated and simply superb. Here are some quotes from his talk:

  • A professional who doesn’t learn to fail, fails to learn
  • If a language is more typed, you type less (e.g. Scala). If a language is less typed, you type more (e.g. Java)
  • Standardization before innovation is a bad idea, that’s why EJB 1.0 suck so bad
  • It’s the lack of clear business objective, not lack of money & time that leads to failure
  • Passion, Competency, Responsibility – 3 things that can make your company succeed

I’m certainly looking forward to his keynote at Spark IT 2010 next week.

Finally some pictures from the conference:

And the complete album is available at:

Here is a brief number summary of the 2-week conference circuit starting next week:

  • 3 conferences
  • 8 sessions + 1 hands-on workshop
  • 2 cities
  • 6 days
  • 3 Hotels
  • 3 Airlines
  • Infinite meet/greet sessions

And then of course there is another one on Java EE 6 & GlassFish in Dallas on April 5, thank you GCA :-)

Technorati: conf glassfish v3 javaee atlanta devnexus ajug gca

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

March 3, 2010

Java EE 6 & GlassFish – Spark IT 2010, Ruby Conf India 2010, Tech Days 2010

Filed under: eclipse, glassfish, javaee, netbeans — arungupta @ 10:19 am

Java EE 6 & GlassFish are swimming across the globe to participate in three different conferences in March 2010.

Spark IT 2010 is an inaugural conference and a joint initiative of CIOL, India’s largest IT portal and PCQuest, India’s leading magazine for IT professionals. You’ll hear about:

  • Java EE 6 & GlassFish (12:05 – 12:50pm, Mar 18)
  • Improving engineering process through Hudson (3:30 – 4:15pm, Mar 18)
  • GlassFish Toolapalooza (2:40 – 3:25pm, Mar 19)
  • Rails on GlassFish workshop (Mar 19)

Check Spark IT 2010 website for the latest updates. See the Agenda, Speakers, Venue Layout, follow the updates on @sparkit2010 and register now!

Ruby Conf India 2010 is India’s first RubyConf and is presented by Ruby community in India (which seems to be growing) and supported by RubyCentral. There are lots of great speakers Matz, Chad, Obie, Nick, and Ola. And of course, you’ll hear about:

  • GlassFish supports multiple Ruby frameworks … really ? (2:00 – 2:45pm, Mar 21)

Check Ruby Conf 2010 website for the latest updates. See the Agenda, Venue (Royal Orchid Hotel), follow the updates on @rubyconfindia and register now!

Don’t miss out on Sambar/Dosa and Mavalli Tiffin Room while in Bangalore :-)

Tech Days 2010 at Hyderabad is biggest of all the Tech Days events. Other than Dum Biryani, Minarets, and Pearls, you’ll hear about Java EE 6 platform and toolshow, OSGi, and Java Persistence API 2. The Agenda (to be updated) has all the details and James Gosling is going to be there as well!

Check Tech Days 2010 website for the latest updates. The venue (Hyderabad International Convention Center) is indeed very impressive so don’t miss out and register now!

Check out reports from Tech Days 2009 (1, 2) and Tech Days 2008 (1, 2, 3, 4, 5, 6, 7).

Here is the current speaking schedule:

And as always, feel free to join me for a run :-)

Technorati: conf glassfish javaee bangalore hyderabad sparkit2010 rubyconfindia techdays hudson

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

February 10, 2010

TOTD #122: Creating a JPA Persistence Unit using NetBeans 6.8

Filed under: glassfish, javaee, netbeans — arungupta @ 6:03 am

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!

  1. Configure GlassFish for using the MySQL sample database (sakila) as described in TOTD #121.
  2. Add the GlassFish instance in NetBeans IDE using "Services" panel.
  3. Create JPA entities using NetBeans IDE.

    1. Create a Java class library:

      Our ultimate goal is to create a reusable JAR file and that’s why this project type is chosen.

    2. Specify the name of project as "SakilaPU":

    3. Right-click on the project and select "New", "Entity Classes from Database …" to initiate the process of entity generation:

    4. Choose the database connection as:

      If not configured, then can be easily done by clicking on "New Database Connection …" in the list box.

      1. Click on "Add All >>" to generate the mapped JPA entities for all tables and views.
      2. The views do not have primary keys and will need to be appropriately annotated (described later).
      3. Click on "Next >".
    5. Give the package name as:

      and specify the package name as "sakila". Click on "Create Persistence Unit …".

    6. Change the default PU name from "SakilaPUPU" to "SakilaPU":

      and click on "Finish". Notice that "EclipseLink", the Reference Implementation of JPA 2.0, is used as the persistence library.

    7. Add "@javax.persistence.Id" 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 "views" are defined with a primary key.

    8. Right-click on the project and select "Clean & Build". This generates "dist/SakilaPU.jar" 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.

In order for this PU to be used in an application server (such as GlassFish) that is pre-configured with a JDBC resource, the "persistence.xml" needs to be changed to:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
 <persistence-unit name="SakilaPU" transaction-type="JTA">
 <jta-data-source>jdbc/sakila</jta-data-source>
 <properties/>
 </persistence-unit>
</persistence>

The JDBC resource name is specified using <jta-data-source>.

The key items to note about this pre-built JAR:

  • Persistence Unit Name: "SakilaPU"
  • All classes are in "sakila.*" package.
  • Each class has a pre-defined "<CLASS-NAME>.findAll" named query that returns all elements from the underlying view/table.

This JAR can be installed to your local Maven repository as:

mvn install:install-file -Dfile=SakilaPU.jar -DgroupId=org.glassfish.samples -DartifactId=sakilapu -Dversion=1.0 -Dpackaging=jar -DgeneratePom=true

and then included in your "pom.xml" as:

 <dependency>
   <groupId>org.glassfish.samples</groupId>
   <artifactId>sakilapu</artifactId>
   <version>1.0</version>
   <scope>compile</scope>
 </dependency>

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

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

January 30, 2010

Developer Tools Strategy by Oracle+Sun: NetBeans & Hudson to stay!

Filed under: eclipse, netbeans — arungupta @ 6:26 am

Hear Ted Farrell, Chief Architect and Senior Vice President talk about Oracle and Sun Java Developer Tools Strategy.

Here is a summary for those who want a quick juice:

  • Productivity With Choice

    • Choose the right tool set for your needs
    • Shared infrastructure across tools with Hudson, Oracle TPC, Subversion. Bugzilla, Maven, etc.
    • NetBeans continues with strong Java focus
    • Combine and integrate the best features across tools
  • More resources for Developers

    • Netbeans.org, java.net, otn.oracle.com
    • More courses/training on Java technologies
    • More conferences around the world
    • Better products from expanded R&D and partner ecosystem
    • Larger combined developer community

Here is a lovely snapshot from the webcast …

Some more detailed points captured from the webcast …

  • If you are a NetBeans user today, you’ll continue to be a NetBeans user after acquisition.
  • Increase the investment in Hudson, lots of synergy with Team Productivity Center.
  • Discontinue the public interface for kenai.com for now, fits very well with some internal projects. Read more about the future of kenai.com.
  • Want to make the best Java IDE for the Java platform. NetBeans platform is very important to lot of customers.
  • For NetBeans, turn to community for external non-Java like Dynamic Languages. Invest more in the infrastructure and community.
  • netbeans.org unchanged
  • Community participation is key for:

    • NetBeans plug-ins
    • Building apps on NetBeans Platform
    • Emerging, Dynamic Languages
    • Dialog, interaction, lists, docs, events, JUGS, etc
  • No licensing changes

    • Versions of NetBeans <= 6.7 follow Sun policy
    • Versions of NetBeans >= 6.8 follow the Oracle policy (complete details)

The webcast also talks about JavaOne being co-located with Oracle Open World (Se 19-23, 2010) and also expanding to Brazil, Russia, India, and China.

oracle.com/tools for more details. The complete list of webcasts + slides from yesterday’s event are now available.

There are several other articles (in no particular order):

Also check out the FAQ for Developer Community.

Technorati: sun oracle netbeans kenai hudson strategy

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

January 21, 2010

TOTD #119: Telnet to GlassFish v3 with NetBeans 6.8 – “Could not open connection to the host”

Filed under: glassfish, netbeans — arungupta @ 6:00 pm

As explained in TOTD #118, one of the ways to manage OSGi bundles in GlassFish is by giving the command "telnet localhost 6666".

This straight forward command works fine if you installed either the Sun GlassFish Enterprise Server or the GlassFish community bits. The "domain.xml" in both of them is pre-configured for the telnet port to 6666 using the "jvm-options" as shown below:

<jvm-options>-Dosgi.shell.telnet.port=6666</jvm-options>

However if you installed GlassFish as part of NetBeans 6.8, then you might see an error message as shown below:

C:\Users\Arun>telnet localhost 6666
Connecting To localhost...Could not open connection to the host, on
port 6666: Connect failed

This error is more prominent in Windows Vista / 7 because of the Windows User Account Control (UAC). Or anywhere where GlassFish is installed in a directory that require root/administrator/sudo access to read/write. This Tip Of The Day will explain how to workaround this issue.

The default NetBeans installation directory is "C:\Program Files\NetBeans 6.8" and GlassFish goes in "C:\Program Files\sges-v3". At first start of NetBeans (typically as a non-Administrator), it tries to register the pre-configured domain in GlassFish installed in "C:\Program Files". But the non-Adminstrator user do not have read/write access to "C:\Program Files" and any sub-directories. So NetBeans create a new "personal" domain and assign a random port available at that moment for telnet. It shows all the ports assigned during the domain creation as shown below:

The image shows the port number "22007" for OSGI_SHELL.

How do you find that port later ? – Go to "Services" tab, expand "Servers", right-click on "Personal GlassFish v3 Domain", select "Properties" from the popup menu to see the following window:

The "Domains folder" shows the directory location of newly created domain and "Domain Name" has the domain name. The exact assigned port can be found by looking at "Domains folder"\"Domain Name"\config\domain.xml. On my Windows7, it showed the following line:

<jvm-options>-Dosgi.shell.telnet.port=22007</jvm-options>

So I tried "telnet localhost 22007" and voila, it worked!

Some other possible solutions that will work:

  1. Delete ".netbeans" directory and restart NetBeans by right-clicking on selecting "Run as administrator". This will provide the required rights for NetBeans to read/write "C:\Program Files\sges-v3\glassfish\domains\domain1" directory. And so instead of creating a new "personal" domain, it’ll register the existing domain in "\Program Files\sges-v3\glassfish". Then "telnet localhost 6666" will work as expected.
  2. During NetBeans installation, specify GlassFish installation directory in a user directory such as:

    This will ensure that NetBeans will have required privileges to read/write the "domains\domain1" directory.

  3. Delete the "Personal GlassFish v3 Domain" and register a new instance that is already installed in a user directory.
  4. Disable UAC.

A complete archive of all the TOTDs is available here.

Technorati: totd netbeans glassfish v3 felix osgi telnet

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

October 12, 2009

Oracle Open World 2009 – Day 2 Report

Filed under: eclipse, glassfish, javaee, netbeans — Tags: , — arungupta @ 11:01 pm

Following from Day 1, the Day 2 started with Charles Phillips and Safra Catz keynote. The keynotes at Open World are significantly different from JavaOne or any other developer conference I’ve attended so far. Of course they are expected to be because Open World is not primarily a developer’s conference. Oracle Develop (OD) certainly closely mimic any of the conferences I’ve typically attended. My "exhibitor" badge restricted me from attending any of the sessions at OD though :-(

Here are some interesting statistics about the conference:

5 content streams (Database, Applications, Industries, Management & Infrastructure, & Middleware)
314 demo kisosk
401 partners & customer exchibiting
1966 educational sessions (10% more than last year)
4500 Oracle developers/experts for you
81,266 hotel room nights
170,000 cups of coffee
182,000 online participation

Here are some interesting sightings from the Open World exhibitor pavilion:

  • Tata Consultancy Services, Infosys, HCL, Wipro, Mahindra Satyam, Birlasoft, Cognizant and a host of other companies based in India are exhibiting in the pavilion. This is a pleasant surprise from JavaOne which typically does not see these many companies out of India.
  • Poker, Ducati, Glider, Beatles Guitar, Sumo wrestler, Callaway Golf, Mini Cooper and other similar sightings were spotted. Check out complete set of images here.
  • Lot more attendees are wearing a suit, quite unlike JavaOne or RailsConf which is typically denim/t-shirt rich.

On a personal front, everything that possibly could went wrong as part of the demo installation yesterday and rehearsal for my talks earlier today. NetBeans was not able to connect to the Oracle database (couple of machine restarts solved that), GlassFish Tools Bundle for Eclipse was timing out attempting to start GlassFish (removing workspace solved that problem), NetBeans’s RESTful tooling not recognizing JPA entities, and also found a blocking bug (issue #10166) in deploying Rails app to latest GlassFish promoted build. These demos have worked seamlessly for me all the time time and fortunately worked well during the talk.

My talk at the Unconference on Creating Quick and Powerful Web applications with Oracle, GlassFish and NetBeans/Eclipse went well. It was truly an unconference event with no projector or mic in the presentation room. But the small attendance allowed us to huddle around the table and luckily all the demos worked seamlessly. The slides are available at:

Several demos shown in the talk are available at:

The slides have pointers to several other demos as well. Also showed the simplicity of Java EE 6 development using Eclipse in Java Platform, Enterprise Edition: The Foundation and Future of Your Enterpise.

The day concluded with OTN Night in Howard St tent. Check out a brief video from the event:

Here are some pictures from earlier today:

And the evolving album at:

If you are not able to attend in person, then you can follow OOW Blogs, Open World Live, @OpenWorld (twitter), Community tweets with #oow.

Back tomorrow on Day 3 with more pictures :-)

Technorati: conf oracle openworld oow glassfish javaee netbeans eclipse

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

October 8, 2009

TOTD #112: Exposing Oracle database tables as RESTful entities using JAX-RS, GlassFish, and NetBeans

Filed under: frameworks, glassfish, javaee, netbeans, totd, webservices — Tags: , , , , — arungupta @ 2:29 am

This Tip Of The Day explains how to expose an existing Oracle database table as a RESTful Web service endpoint using NetBeans tooling and deployed on GlassFish.

Lets get started!

  1. Configure GlassFish v3 10/7 or a later nightly in a recent NetBeans 6.8 build (latest nightly). As issue# 9885 is fixed, so copy ojdbc6.jar in the "domains/domain1/lib/ext" directory.
  2. Create a Web application

    1. Create a new "Web application" and name the project "RestfulOracle":

      click on "Next >".

    2. Choose the newly added server and "Java EE 6 Web" as the Java EE version:

      and click on "Finish".

  3. Create JPA entities for "HR" schema. The steps outlined below uses NetBeans solely for creating the JPA entities. Alternatively, TOTD #108 explains how to define a JDBC connection pool and JDBC resource using "asadmin" CLI and then use that resource from within NetBeans. Either way, the JDBC resource is stored in the underlying "domain.xml".

    1. Right-click on the project and select "New", "Entity Classes from Database…".
    2. In "Data Source:" select "New Data Source…" as shown below:

    3. Specify the JNDI name as "jdbc/hr" and choose the pre-configured database connection as shown below:

      TOTD #107 explains how to configure Oracle database in NetBeans.

    4. In the list of "Available Tables:", select "EMPLOYEES" and click on "Add >" to see the following:

      Notice the list of related tables are included as well. Click on "Next >".

    5. Specify the package name as "model".
    6. Click on "Create Persistence Unit…", take the defaults, and click on "Create":

      and click on "Finish". Notice EclipseLink, the reference implementation for JPA 2.0, is used as the persistence provider. This generates POJOs that provide database access using JPA 2.0 APIs. These APIs are included as part of the Java EE 6 platform.

  4. Create RESTful entities

    1. Right-click on the project and select "RESTful Web Services from Entity Classes…":

    2. Select "Employees (model.Employees)" from "Available Entity Classes:" and click on "Add >" to see the following:

      click on "Next >", take the defaults, and click on "Finish". This generates a bunch of wrapper classes using JAX-RS to expose the JPA Entity classes as RESTful Web services. JAX-RS 1.1 is also included as part of the Java EE 6 platform.

  5. Run the Web service

    1. Right-click the project and select "Test RESTful Web Services":

      This deploys the created Web application on the selected GlassFish build and displays the following page in the default browser:

    2. Click on "deparmentss" and then on "Test" button to see the output as:

      Clicking the "Test" button issues a GET request to "http://localhost:8080/RestfulOracle/resources/departmentss". This uses the generated JAX-RS wrapper classes to talk to the database using JPA entity classes and query the first 10 rows from the "DEPARTMENTS" table. The response is then JSON formatted using JAX-RS wrapper classes and is returned to the requesting page which then displays it nicely formatted in the table. It also shows l-level deep department’s relationship to other entities. If the "expandLevel" on the above page is set to "0", then the following output is shown:

      The "Raw View" (JSON data) of the original output looks like:

      Notice this is the raw JSON output generated by the JAX-RS wrapper classes. The "Http Monitor" traffic looks like:

      The format of data returned can be changed from "application/json" to "application/xml" as shown below:

      And even a POST request can be generated.

Do you have the need to expose your Oracle database tables as RESTful entities ?

A complete archive of all the TOTDs is available here.

This and other similar applications will be demonstrated at the upcoming Oracle Open World.

Technorati: totd oracle database glassfish v3 netbeans javaee jax-rs jpa rest

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

October 3, 2009

Silicon Valley Code Code Camp 2009 Trip Report

Filed under: eclipse, glassfish, netbeans — arungupta @ 11:30 pm

The Foothill college was sprawling with developers, architects, engineers, et al from all over the San Francisco Bay Area to attend the Silicon Valley Code Camp 2009. This was my third speaking engagement (2008, 2007) and the code camp has certainly matured over the last years. The attendance is steadily growing and the quality of sessions is become more mature as well.

I presented on Java EE 6, GlassFish, and Eclipse Tooling for GlassFish/Java EE 6 and the slides are available below:

and

Both the talks were demo intensive and showed Deploy-on-Save, Preserving session state across deployments, Java EE 6 wizards in NetBeans (1, 2, 3, 4, 5) and Eclipse (1, 2, 3), Metro JAX-WS Web services development in Eclipse, GlassFish v3 Monitoring, GlassFish v3 REST interface to management and monitoring and many others. All the demos are available as screencasts and/or blog entries and the complete set of links are listed in the presentations.

Here are some pictures from the event:

And the complete album at:

That’s it folks, see ya next year!

Technorati: siliconvalleycodecamp svcc glassfish javaee eclipse

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

October 1, 2009

TOTD #108: Java EE 6 web application (JSF 2.0 + JPA 2.0 + EJB 3.1) using Oracle, NetBeans, and GlassFish

Filed under: frameworks, glassfish, javaee, javaserverfaces, netbeans, totd — Tags: , — arungupta @ 11:00 am

TOTD #106 explained how to install Oracle database 10g R2 on Mac OS X. TOTD #107 explained how to connect this Oracle database using NetBeans. This Tip Of The Day will explain how to use the sample HR database (that comes with Oracle database server) to write a simple Java EE 6 application.

This application will use Java Server Faces 2.0 for displaying the results, Enterprise Java Beans 3.1 + Java Persistence API 2.0 for middle tier, and Oracle database server + GlassFish v3 as the backend. The latest promoted build (65 of this writing) will not work because of the issue #9885 so this blog will use build 63 instead.

Several improvements have been made over NetBeans 6.8 M1 build and this blog is using the nightly build of 9/27. The environment used in this blog is:

  • NetBeans 9/27 nightly
  • GlassFish v3 build 63
  • Oracle database server 10.2.0.4.0 R2 on Mac OS X
  • Oracle JDBC Driver type 4 (ojdbc6.jar)

Lets get started!

  1. Configure GlassFish v3 with JDBC connection

    1. Download and unzip build 63.
    2. Download ojdbc6.jar and copy to "glassfishv3/glassfish/domains/domain1/lib/ext" directory.
    3. Start the Application Server as:

      ./bin/asadmin start-domain --verbose &
      
    4. Create a JDBC connection pool as:

      ./bin/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
      

      and verify the connection pool as:

      ./bin/asadmin ping-connection-pool jdbc/hr
      
    5. Create a JDBC resource as:

      ./bin/asadmin create-jdbc-resource --connectionpoolid jdbc/hr jdbc/hr
      
  2. Configure GlassFish v3 build 63 in NetBeans

    1. In NetBeans IDE "Services" panel, right-click on "Servers" and click on "Add Server…". Choose "GlassFish v3" and provide a name as shown below:

    2. Click on "Next >" and specify the unzipped GlassFish location as:

      and click on "Finish".

  3. Create the Java EE 6 application

    1. In "Projects" pane, right-click and select "New Project…".
    2. Choose "Java Web" and "Web Application" and click on "Next". Choose the project name as "HelloOracle":

      and click on "Next >".

    3. Select the recently added GlassFish v3 server and choose "Java EE 6 Web" profile:

      and click on "Next >". Notice "Java EE 6 Web" profile is chosen as the Java EE version.

    4. Select "JavaServer Faces" on the frameworks page:

      and click on "Finish". Notice the JSF libraries bundled with the App Server are used.

  4. Create the Java Persistence Unit

    1. Right-click on the project, select "New", "Entity Classes from Database…":

    2. From the Data Source, select "jdbc/hr" as shown:

      This is the same JDBC resource created earlier. Select "EMPLOYEES" from the Available Table, click on "Add >" to see the output as:

      The related tables are automatically included. Click on "Next >".

    3. Click on "Create Persistence Unit …" and take all the defaults and click on "Create".
    4. Specify the package name as "model":

      and click on "Finish". This generates a JPA-compliant POJO class that provide access to tables in the underlying Oracle database. The class name corresponding to each table is shown in the wizard.

  5. Create Enterprise Java Beans

    1. Right-click on the project and select "New Class…".
    2. Specify the class name as "EmployeesBean" and package as "controller", click on "Finish".
    3. Annotate the class to make it an Enterprise Java Bean and a JSF Managed Bean as:

      @javax.ejb.Stateless
      @javax.faces.bean.ManagedBean
      

      Notice, the EJB is bundled in the WAR file and no special type of modules are required. Java EE 6 provides simplified packaging of EJB which makes it really ease to use.

      Also this application is currently using JSF managed bean but will use JSR 299 (aka Web Beans) in a future blog.

    4. Inject the Persistence Unit by adding the following variable:

      @PersistenceUnit
      EntityManagerFactory emf;
      
    5. Add a new method to retrieve the list of all employees as:

      public List getEmployees() {
       return em.createNamedQuery("Employees.findAll").getResultList();
      }
      

      "Employees.findAll" is a default NamedQuery generated by NetBeans and makes it easy to query the database. Several other queries are generated for each mapped JPA class, such as "Employees.findByEmployeeId" and "Employees.findByFirstName". Custom queries can also be created and specified on the POJO class.

      The completed class looks like:

      @Stateless
      @ManagedBean
      public class EmployeesBean {
      
       @PersistenceContext
       EntityManager em;
      
       public List getEmployees() {
       return em.createNamedQuery("Employees.findAll").getResultList();
       }
      }
      
  6. Use EJB in the generated JSF page

    1. JSF 2 uses Facelets as the templating mechanism and NetBeans generate a simple "index.xhtml" file to start with. Expand "Web Pages" and open "index.xhtml".
    2. Replace the body template with:

      <h1>First Java EE 6 app using Oracle database</>
      <h:dataTable var="emp" value="#{employeesBean.employees}" border="1">
       <h:column><h:outputText value="#{emp.lastName}"/>, <h:outputText value="#{emp.firstName}"/></h:column>
       <h:column><h:outputText value="#{emp.email}"/></h:column>
       <h:column><h:outputText value="#{emp.hireDate}"/></h:column>
       </h:dataTable>
      

      It uses JSF value expressions to bind the Enterprise Java Bean and dumps the HTML formatted name, email, and hire date of each employee in the database.

  7. Run the project: Right-click on the project and select "Run" to see the output at "http://localhost:8080/HelloOracle/" as:

So we can easily create a Java EE 6 application using NetBeans, Oracle, and GlassFish.

A complete archive of all the TOTDs is available here.

This and other similar applications will be demonstrated at the upcoming Oracle Open World.

Technorati: totd oracle database glassfish v3 javaee javaserverfaces ejb jpa netbeans oow

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot

September 30, 2009

TOTD #107: Connect to Oracle database using NetBeans

Filed under: javaee, netbeans, totd — arungupta @ 3:32 am

TOTD #106 explained how to install Oracle database 10g R2 on Mac OS X. This Tip Of The Day will explain how to connect Oracle database with NetBeans to leverage all the goodness provided by NetBeans for Java EE application development, Rails, and others.

  1. Download Oracle JDBC Drivers, specifically ojdbc14.jar. (ojdbc6.jar is recommended to be used with GlassFish v3).
  2. Using NetBeans 6.8 M1, in Services tab, right-click on "Databases" and select "New Connection…" as shown:

  3. Expand "Name:" and select "New Driver…":

  4. Click on "Add…" and choose the recently downloaded JDBC driver JAR file as shown below:

    and click on "OK".

  5. Enter the database values as shown below:

    The password is "hr" for the sample HR database. Clicking on "Show JDBC URL" also shows the complete JDBC URL. Click on "OK".

    You may have to unlock the "hr" user by giving the command:

    ALTER USER HR IDENTIFIED BY hr ACCOUNT UNLOCK;
    

    as explained in TOTD #106.

  6. Select the "HR" schema as shown below:

    and click on "OK". The complete list of schemas is now shown in the "Databases" node as shown below:

  7. Expand the "HR" node and the complete list of tables is visible now:

    Expanding each table shows you the complete definition as shown:

  8. Right-click on "COUNTRIES" table and select "View Data…"

    and the result is shown as:

    Additionally, you can execute any SQL command by selecting "Execute Command…":

A complete archive of all the TOTDs is available here.

Subsequent blogs will show how to write a Java EE application to access the Oracle database.

Technorati: totd oracle database netbeans

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • email
  • StumbleUpon
  • Technorati
  • Twitter
  • Slashdot
Older Posts »

Powered by WordPress