1 2 3 Previous Next 31 Replies Latest reply: Aug 3, 2009 5:11 AM by 843833 Go to original post RSS
      • 30. Re: Running Petstore 2.0 with jboss
        nevermind, i figured out how to download the file. just clicked on the right text area box in attachments to download it.
        • 31. Re: Running Petstore 2.0 with jboss
          I also have been working on getting petstore2.0 to work with jboss. I haven't really adapted the antscripts to behave as I would like them to but I did get things to workt. For this I did the following:

          1. I set up the javadb separately, I used http://db.apache.org/derby/docs/dev/getstart/ to get to know things. I also chose to use the DerbyClient instead of the Embedded driver, which (I think) will be closer to an actual production environment.
          a. set up everything (once)
          b. create and fill the petstore database (once)
          ij>CONNECT 'jdbc:derby:petstore;create=true';
          ij>run 'petstore.sql';
          c. start the Networkserver (every time)
          java -jar $DERBY_HOME/lib/derbyrun.jar server start
          d. make sure that there is a derby-ds.xml in the jboss deploy directory
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- The Derby embedded database JCA connection factory config
          $Id: derby-ds.xml,v 2004/11/03 13:28:39 loubyansky Exp $ -->
                <!-- The jndi name of the DataSource, it is prefixed with java:/ -->
                <!-- Datasources are not available outside the virtual machine -->
                <!-- for in-process persistent db, saved when jboss stops. The
                org.jboss.jdbc.DerbyDatabase mbean is necessary for properly db shutdown -->
                <!-- The driver class -->
                <!-- The login and password -->
                <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
                <!-- The maximum connections in a pool/sub-pool -->
                <!-- The time before an unused connection is destroyed -->
                <!-- Whether to check all statements are closed when the connection is returned to the pool,
                     this is a debugging feature that should be turned off in production -->
                <!-- This mbean can be used when using in process persistent derby -->
                <!-- <depends>jboss:service=Derby</depends> -->
             <mbean code="org.jboss.jdbc.DerbyDatabase" name="jboss:service=Derby">
                <attribute name="Database">petstore</attribute>
          e. and the persistence.xml
          <?xml version="1.0" encoding="UTF-8"?>
          <!-- Copyright 2006 Sun Microsystems, Inc.  All rights reserved.  You may not modify, use, reproduce, or distribute this software except in compliance with the terms of the License at: 
           $Id: persistence.xml,v 1.7 2007/04/18 19:26:07 smitha Exp $ -->
          <persistence version="1.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_1_0.xsd"> 
              <persistence-unit name="PetstorePu">
                  <description>Petstore Persistence Unit</description>
                      <property name="hibernate.dialect" value="org.hibernate.dialect.DerbyDialect"/>
                      <property name="hibernate.connection.username" value="APP"/>
                      <property name="hibernate.connection.password" value="APP"/>
                      <property name="hibernate.format_sql" value="true"/>
          Maybe the username and password here are not necessary as they are already in the derby-ds.xml. It is important to note that, in Derby, when creating a database without specifying credentials they default to 'APP'. And as you are required to fill the username and password tag in the xxx-ds.xml you should use these.
          f. make sure you put the derbyclient.jar (its in the lib directory of Derby when you download it) in the jboss classpath.

          2. Once I got the petshop running correctly I still had a problem because I got a LazyInstantiationException when I tried to klik on one of the Tags in the petstore (for example: excellent).
          The problem here is that any instancevariables (or at least collections) are not really instantiated when the object (a Tag in this case) is. To get around this I added a method to the CatalogFacade based on the getTag method which I left untouched.
              public Tag getTagWithPersistentItems(String sxTag) {
                  Tag tag=null;
                  EntityManager em = emf.createEntityManager();
                  List<Tag> tags=em.createQuery("SELECT t FROM Tag t WHERE t.tag = :tag").setParameter("tag", sxTag).getResultList();
                  if(tags != null && !tags.isEmpty()) {
                  // lines inserted to get Items and their Tags instantiated also.
                  for(Item item:tag.getItems()){
                  // end of insert
                  return tag;
          You need to call this new method instead of getTag(xsTag) in line 18 in the tagItemLookup.jsp

          3. You can use the tag runapp to get the petstore.war created and deployed (to the default instance of your jboss, if you followed Mani's specifications in this thread). How ever we need to reorganise the filestructure, as jboss seems to need the Entities to be in an ejb-jar. The structure should be as follows:
              lib    - containing all from the lib directory in the original petstore.war
              META-INF   - containing an application.xml that specifies the webmodule (and the root) as well as the ejb-jar
                   jsps and such (as in the original petstore.war)
                         classes      - containing all classes EXCEPT those that have the @Entity annotation (all in the model package)
              petstore-persistence.jar (the ejb-jar specified in the application.xml)
                    containing all classes with the @Entity annotation (of course in the correct directory structure) that were removed from the war file
          I hope this helps someone out there and that I haven't forgotten anything.
          And if any one has any suggestions or comments, I am all ears ;->.
          1 2 3 Previous Next