Experience Java EE! Using Websphere Application Server Community Edition 2.1
Total Page:16
File Type:pdf, Size:1020Kb
Front cover Experience Java EE! Using WebSphere Application Server Community Edition 2.1 On-ramp to Java EE development Including EJB 3.0, Web services, JMS and Web 2.0 Detailed hands-on tutorials Ueli Wahli Charles P Brown Steven Calello Rafael Coutinho Patrick Gan Cedric Hurst Maan Mehta ibm.com/redbooks International Technical Support Organization Experience Java EE! Using WebSphere Application Server Community Edition 2.1 February 2009 SG24-7639-00 Note: Before using this information and the product it supports, read the information in “Notices” on page xv. First Edition (February 2009) This edition applies to WebSphere Application Server Community Edition (WASCE) Version 2.1, and Eclipse Ganymede, which was used as the integrated development environment for WASCE. © Copyright International Business Machines Corporation 2009. All rights reserved. Note to U.S. Government Users Restricted Rights -- Use, duplication or disclosure restricted by GSA ADP Schedule Contract with IBM Corp. Contents Notices . xv Trademarks . xvi Preface . xvii The team that wrote this book . xviii Become a published author . xx Comments welcome. xxi Part 1. Preliminary activities . 1 Chapter 1. Introduction. 3 1.1 Learn, Experience, Explore! . 4 1.2 Java EE simplified . 7 1.2.1 Objective . 8 1.2.2 Specifications . 9 1.2.3 Implementations . 11 1.2.4 Web services and messaging . 13 1.2.5 Container architecture. 14 1.3 Introduction to the scenario . 19 1.4 Jump start . 22 1.5 Linux variations . 23 Chapter 2. Install and configure software. 25 2.1 Required software . 26 2.2 Hardware requirements. 27 2.3 Software requirements . 28 2.4 Obtaining the software . 29 2.5 Install the software . 31 2.5.1 Install the IBM SDK/JRE (Windows) . 32 2.5.2 Install the IBM SDK/JRE (Linux) . 35 2.5.3 Install WASCE v2.1. 37 2.5.4 Install the Eclipse IDE for Java EE Developers . 41 2.5.5 Install the WASCE Server Adapter v2.1 . 42 2.5.6 Verify the installation . 47 © Copyright IBM Corp. 2009. All rights reserved. iii 2.6 Post configuration in Eclipse . 48 Chapter 3. Configure the development environment. 49 3.1 Learn! . 50 3.2 Extract the sample code file . 52 3.3 Create the WASCE IDE workspace . 53 3.4 Configure the IBM SDK/JRE . 57 3.5 Add the ExperienceJavaEE test server definition . 58 3.5.1 Add the WASCE server runtime definition . 59 3.5.2 Create the ExperienceJavaEE Server definition . 61 3.6 Start the ExperienceJavaEE Server test server . 66 3.6.1 Start the WASCE Administrative Console. 67 3.6.2 Control the server outside of WASCE IDE . 68 3.7 Import the sample code snippets . 69 3.8 Configure user libraries in Eclipse. 71 3.9 IDE preferences . 72 3.10 Explore! . 73 Chapter 4. Prepare the legacy application . 77 4.1 Learn! . 78 4.2 Configure the Derby JDBC driver . 79 4.3 Create the Vacation database. 80 4.4 Create the employee table in the Vacation database . 85 4.5 Populate the Vacation database . 88 4.6 Connect to the Donate database in the WASCE IDE . 89 4.7 Create the WASCE Vacation database data source. 90 4.8 Create the WASCE Donate database data source . 94 4.9 Explore! . 95 Part 2. Core Java EE application . 97 Chapter 5. Create the JPA entities . 99 5.1 Learn! . 100 5.1.1 Entities . 101 5.1.2 Mapping the table and columns . 102 5.1.3 Entity identity. 105 5.1.4 Callback methods and listeners . 109 5.1.5 Relationships. 110 5.1.6 Entity inheritance. 115 5.1.7 Persistence units. 117 5.1.8 Object-relational mapping through orm.xml . 119 5.1.9 Persistence provider . 120 5.1.10 Entity manager . 120 5.1.11 Entity life cycle . 124 iv Experience Java EE! Using WebSphere Application Server Community Edition 2.1 5.1.12 JPA query language . 124 5.2 Jump start . 129 5.3 Create the database connection pool . 129 5.4 Create an enterprise application project . 130 5.5 Create and configure a JPA project . 133 5.5.1 Create the project . 133 5.5.2 Project dependencies . 135 5.5.3 Add dependencies to the EAR deployment plan. 136 5.6 Generate the Employee entity from a table. 138 5.6.1 Create the Employee entity. 138 5.6.2 Verify the persistence.xml file . 141 5.7 Create the Fund entity. 142 5.7.1 Create a JPA project for the Fund entity . 142 5.7.2 Create the Fund entity. 143 5.7.3 Add JPA annotations to the Fund entity . 144 5.7.4 Add a named query to the Fund entity . 145 5.8 Customize the persistence.xml files . ..