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
        843833
        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
          843833
          ron23
          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
          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 1.1.4.1 2004/11/03 13:28:39 loubyansky Exp $ -->
          
          <datasources>
             <local-tx-datasource>
          
                <!-- The jndi name of the DataSource, it is prefixed with java:/ -->
                <!-- Datasources are not available outside the virtual machine -->
                <jndi-name>jdbc/PetstoreDB</jndi-name>
          
                <!-- for in-process persistent db, saved when jboss stops. The
                org.jboss.jdbc.DerbyDatabase mbean is necessary for properly db shutdown -->
                <connection-url>jdbc:derby://localhost:1527/petstore;create=true</connection-url>
                <!-- The driver class -->
                <driver-class>org.apache.derby.jdbc.ClientDriver</driver-class>
          
                <!-- The login and password -->
                <user-name>APP</user-name>
                <password>APP</password>
          
                <!-- The minimum connections in a pool/sub-pool. Pools are lazily constructed on first use -->
                <min-pool-size>5</min-pool-size>
          
                <!-- The maximum connections in a pool/sub-pool -->
                <max-pool-size>20</max-pool-size>
          
                <!-- The time before an unused connection is destroyed -->
                <idle-timeout-minutes>5</idle-timeout-minutes>
          
                <!-- 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 -->
                <track-statements></track-statements>
          
                <!-- This mbean can be used when using in process persistent derby -->
                <!-- <depends>jboss:service=Derby</depends> -->
             </local-tx-datasource>
          <!--
             <mbean code="org.jboss.jdbc.DerbyDatabase" name="jboss:service=Derby">
                <attribute name="Database">petstore</attribute>
             </mbean>
          -->
          </datasources>
          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: 
           http://developer.sun.com/berkeley_license.html
           $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>
                  <provider>org.hibernate.ejb.HibernatePersistence</provider>
                  <jta-data-source>java:jdbc/PetstoreDB</jta-data-source>
                  <non-jta-data-source>java:jdbc/PetstoreDB</non-jta-data-source>
                  <properties>
                      <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"/>
                  </properties>
              </persistence-unit>
          </persistence>
          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.
              @SuppressWarnings("unchecked")
              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()) {
                      tag=tags.get(0);
                  }
                  // lines inserted to get Items and their Tags instantiated also.
                  for(Item item:tag.getItems()){
                      item.getTags().size();
                  }
                  // end of insert
                  em.close();
                  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:
          petstore.ear
              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
              petstore.war
                   jsps and such (as in the original petstore.war)
                   WEB-INF
                         classes      - containing all classes EXCEPT those that have the @Entity annotation (all in the model package)
                         faces-config.xml
                         web.xml
              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
                    META-INF
                         persistence.xml
          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