Skip to main content

Seam On GlassFish With Java Persistence

Posted by rogerk on May 4, 2006 at 2:50 PM PDT



content="text/html; charset=ISO-8859-1">
Seam-GlassFish


In  href="http://weblogs.java.net/blog/rogerk/archive/2006/04/java_ee_sdk_run_1.html">Java
EE SDK Runs Seam I outlined some steps for getting href="http://www.jboss.com/products/seam">Seam (the JBoss
application framework that unifies JSF and EJB 3.0) to run on href="https://glassfish.dev.java.net/">GlassFish with Hibernate as
the persistence layer.  Now, we'll see how we can have Seam
running on GlassFish with the href="https://glassfish.dev.java.net/javaee5/persistence/">Java
Persistence API as the persistence layer.  For completeness,
I'll go over the prerequisites and setup as described in href="http://weblogs.java.net/blog/rogerk/archive/2006/04/java_ee_sdk_run_1.html">Java
EE SDK Runs Seam because their are some subtle differences along
the way.

style="text-decoration: underline;">

Prerequisites:

  1. A working build environment with ant,
    at least JDK 5,
    and GlassFish
    (build 43 or later).
  2. You'll need to use some of the Hibernate libraries that the Seam framework depends on:
    • Download and install href="http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=127784&release_id=405151">Hibernate3
      3.2cr1.
    • Download and install href="http://sourceforge.net/project/showfiles.php?group_id=40712&package_id=156160&release_id=405227">Hibernate
      EntityManager 3.1 beta7 .  Note that style="font-style: italic;">hibernate-entitymanager.jar is not
      required because we'll be using Java Persistence.  However, style="font-style: italic;">hibernate-annotations.jar is still
      required, because the Seam framework uses classes from the Hibernate style="font-style: italic;">validator package.
    • Copy the required hibernate jars into Glassfish lib dir.
      The script href="http://weblogs.java.net/blog/rogerk/archive/copyHibernateLibsJPersist.sh">here
      contains the list of jars.
    • Edit the script to make sure it references your Glassfish and
      Hibernate install directories.
    • Execute the script.

Seam Setup:

  1. Download and install the Seam 1.0beta2 release from href="http://prdownloads.sourceforge.net/jboss/jboss-seam-1.0beta2.zip?download">here. 
    You should see a jboss-seam-1.0beta2 directory.
  2. Get the zip files: href="http://weblogs.java.net/blog/rogerk/archive/seam-core-patch.zip">seam-core-patch.zip
    and href="http://weblogs.java.net/blog/rogerk/archive/seam-booking-jpersist-patch.zip">seam-booking-jpersist-patch.zip

  3. Go to the jboss-seam-1.0beta2 directory and unzip
    seam-core-patch.zip and seam-booking-jpersist-patch.zip.

Compilation Procedure:

  1. Copy <glassfish install dir >/lib/javaee.jar
    to jboss-seam-1.0beta2/lib directory.
  2. Copy jboss-seam-1.0beta2/lib/jboss-common.jar style="font-style: italic;"><glassfish install dir>/lib 
    (needed for JBoss Logger)
  3. Compile Seam core classes:
    • Create an empty jboss-seam-1.0beta2/src/test directory (the
      build file is looking for this directory that is not there from the
      seam zip file).
    • Go to jboss-seam-1.0beta2 directory;  ant;
  4. Compile Seam Booking Application:
    • Copy jboss-seam-1.0beta2/jboss-seam-ui.jar to
      jboss-seam-1.0beta2/examples/booking/resources/WEB-INF/lib
    • Go to jboss-seam-1.0beta2/examples/booking
    • ant

Deploy the application:

  1. Start up Glassfish.
  2. Start the database:  <glassfish
    install dir>
    /bin/asadmin
    start-database
  3. Deploy
    jboss-seam-1.0beta2/examples/booking/build/jboss-seam-booking.ear

Load the database:

  1. Go to jboss-seam-1.0beta2/examples/booking/resources
  2. set your CLASSPATH so that it is:
    • CLASSPATH=<glassfish install dir>/javadb/lib/derbyclient.jar: style="font-style: italic;"><glassfish install dir>/javadb/lib/derbytools.jar: style="font-style: italic;"><glassfish install dir>/javadb/lib/derby.jar:.
  3. java -Dij.driver='org.apache.derby.jdbc.ClientDriver'
    org.apache.derby.tools.ij
  4. At the Derby ij prompt connect to the default database:
    • connect 'jdbc:derby://localhost:1527// style="font-style: italic;"><glassfish install dir>/bin/sun-appserv-samples';
      • For example: connect
        'jdbc:derby://localhost:1527///home/work/glassfish/bin/sun-appserv-samples';
    • run 'import.sql';
  • Now the Seam application tables should be loaded.

Run the application:

  • visit localhost:8080/seam-booking



You can refer to href="http://weblogs.java.net/blog/rogerk/archive/2006/04/java_ee_sdk_run_1.html">Java
EE SDK Runs Seam for an explanation of the Seam core
modules and the Seam Booking application modules that required
modification.  Those modifications are essentially the same with
the exception of the following modifications to some Booking
application modules:



    examples/booking/resources/META-INF/persistence.xml

            style="font-style: italic;">---->
updated for application with
GlassFish
and Java
Persistence

   
examples/booking/src/org/jboss/seam/example/booking/BookingListAction.java

   
examples/booking/src/org/jboss/seam/example/booking/HotelBookingAction.java

   
examples/booking/src/org/jboss/seam/example/booking/LoginAction.java

   
examples/booking/src/org/jboss/seam/example/booking/RegisterAction.java style="font-style: italic;">

           style="color: rgb(255, 0, 0);">----> made SQL queries complete for
Java Persistence. 

               
     








Related Topics >>