The Source for Java Technology Collaboration
User: Password:



Brian Leonard

Brian Leonard's Blog

The Best Feature of the Upcoming NetBeans IDE 5.5 (Part 3)

Posted by bleonard on May 23, 2006 at 07:54 AM | Comments (9)

Last month, my colleague Geertjan wrote a couple of pretty popular blog entries:The Best Feature of the Upcoming NetBeans IDE 5.5 (Part 1) and (Part 2). It basically showcases 2 new wizards in NetBeans 5.5: Entity Classes from Database and JSF Pages from Entity Class, that when run back to back essentially create a fully functional CRUD (Create, Read, Update, Delete) application. I was curious how this would work with JBoss, so below for you I document my experiences.

Getting Started
  • Download and install the NetBeans 5.5 Beta.
  • Download and install JBoss 4.0.4. During installation, be sure to select the ejb3 profile.
Step 1: Add the JBoss Server to NetBeans
  1. Switch to the Runtime tab and right-click the Servers node to add a server.



  2. Select JBoss Application Server 4 from the Server drop down list. Change the name to JBoss Application Server 4.0.4.



  3. Complete the Add Server wizard.
  4. Stop the Sun Java System Application Server if it is running (both servers use http port 8080 as their default).
  5. Right-click the new JBoss server node and choose Start:


Step 2: Create the Project

JBoss doesn't ship any sample data with it's HSQLDB. However, there are a few system tables in place to support JMS, so to keep things as simple as possible, we'll go with one of those: JMS_USERS.

  1. Create a New Web Application Project named JMSUserEditor. Be sure to select JBoss as the Server (Note, although JBoss supports components of the Java EE 5 specification, notably EJB 3.0, JBoss 4.0.4 is a J2EE 1.4 compliant application server. Therefore, Java EE 5 is not an available option for J2EE Version.). Also, uncheck the option to Set Source Level to 1.4, as we will be using annotations which require Java 5.0.



  2. On Step 3 of the wizard, Frameworks, be sure to select Java Server Faces and click Finish.
Step 3: Prepare the Project for JBoss

There are a couple of additional steps we need to take in order for the project to run successfully on JBoss. Issues have been filed and these steps will not be necessary with the 5.5 final release.

  1. Remove the JSF and JSTL libraries from the project (Issue 76733). Open the Project Properties, select the Libraries node and Remove the JSF and JSTL libraries from the project.



  2. Add the MyFaces Context Listener to web.xml (Issue 74392). Open the web.xml and expand the Web Application Listeners node. Click Add and add the org.apache.myfaces.webapp.StartupServletContextListener class.


  3. Press F6 to test run the project. If you can load the page that says Java Server Faces, your project is set up correctly:

Step 4: Setup the Database
Follow the steps from this blog entry to set up HSQLDB to run in server mode. This will allow the wizards in the next step to connect to the database. It will also allow you to use NetBeans' database explorer tools to browse the data.

Step 5: Create the Persistence Unit
  1. Press Ctrl+N to create a new file and select the Persistence Category > Persistence Unit.
  2. Set the Persistence Unit Name to default and click Finish.
  3. Press Alt+Shift+Right to open the XML view and replace the persistence unit with the following:
  <persistence-unit name="default">
<jta-data-source>java:/DefaultDS</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value=""/>
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
</properties>
</persistence-unit>
 
Step 6: Create the Entity Classes
  1. Press Ctrl+N to create a new file and select the Persistence Category > Entity Class from Database File Type.
  2. Select the Database Connection jdbc:hsqldb:hsql://localhost:1701 [sa on PUBLIC] and the JMS_USERS table.



    Click Next.

  3. Set the Package to entity and click Finish.
Step 7: Create the JSF Pages
  1. Press Ctrl+N to create a new file and select the Persistence Category > JSF Pages from Entity Class File Type.
  2. Add the JmsUsers Entity Class to the Selected Entity Classes. Click Next.
  3. Set the Package to controller and click Finish.
Step 8: Run Your Application
  1. Press F6 to run the application.

Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • Very cool. But... guess what? I've got the whole story working on Tomcat, using Derby (thanks to Glassfish integration). How cool is it that TopLink includes everything from JavaEE that I need for persistence? Only additional step was to manually include the Java DB Driver from the Library Manager (where it is bundled). The other libraries had to be added manually too (JSF and TopLink). Persistence worked out of the box.

    Posted by: geertjan on May 24, 2006 at 07:43 AM

  • Geertjan, great! So then I guess we can all look forward to Part 4 in this series?

    Posted by: bleonard on May 24, 2006 at 11:16 AM

  • For Sun Application Server 7 and 8.x, the same steps as in Tomcat should work as well (Modulo some security settings maybe?) Worth trying when you are doing the Tomcat tests :-) Of course, JDK 1.5 has to be used by the container.

    Ludo

    Posted by: ludo on May 24, 2006 at 05:50 PM

  • Geertjan,

    This should obviously work in Tomcat as there is no difference between JBoss and Tomcat servlet containers. JBoss uses Tomcat as a servlet container. Though, the configuration steps may vary.

    Cheers,
    Arul

    Posted by: aruld on May 30, 2006 at 03:53 AM

  • Bleonard,

    I created a PU using TopLink and it worked for me. No need to include ehcache-1.2.jar as a dependancy mentioned in Step 8.1.
    I am curious about your Step 5. Its not very clear to me. Could you please explain further?

    Thanks,
    Arul


    oracle.toplink.essentials.ejb.cmp3.EntityManagerFactoryProvider
    entity.JmsUsers







    Posted by: aruld on May 30, 2006 at 03:58 AM

  • Step 5 just defines the persistence unit required to talk to JBoss' HSQLDB. It should be similar to the one you created using TopLink (sans the Hibernate references)

    Posted by: bleonard on May 30, 2006 at 06:10 AM

  • Very impressive, is implemented quite easily, even easier with Netbeans 5.5 Beta 2. Did anyone of you encounter the "JTA EntityManager cannot access a transactions" message? I seem to have a configuration problem which causes the application failing to open a transaction when writing to the database. Reading is no problem. Could you maybe publish a list of the important configuration files/values? Cheers

    Posted by: rschlege on August 02, 2006 at 07:48 AM

  • rschlege: Did you get the 'JTA EntityManager cannot access a transactions" message working through the example in my blog? if not, post your use case and I'll take a look at it.. Brian.

    Posted by: bleonard on August 06, 2006 at 06:24 PM

  • Excellent article! I did encounter problems in Netbeans, mostly due to a bug in the New Persistence Unit wizard... had to use TopLink and then change it later, and then restart JBoss a few times... but it worked.

    Posted by: narve on September 06, 2006 at 03:11 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds