Tutorial: Adding a finder to an existing entity bean
Attention: This tutorial is currently under revision. The content might contain errors or inaccuracies. Subscribe to this page to be notified when an updated version is available.
In this tutorial, you add a finder to an existing entity bean. By default, the order status page displays a customer's orders sorted by order number. In this tutorial, we will add a finder to the Order entity bean to sort a customer's orders by the time the order was placed, then modify the store JSP page to use the new finder.
Learning objectives
- Add a finder to an entity bean to a WebSphere Commerce entity bean.
Due to the fact that the tutorial customization approach modifies existing WebSphere Commerce code, a migration issue arises when a new version of WebSphere Commerce is released. If you wish to retain the changes you make when customizing an entity bean in this way, be aware of the code maintenance implications. For more information about the implications of extending entity beans, see Extending the WebSphere Commerce object model with entity beans .
Time required
Expect this tutorial to take about one hour to complete.
You can load the completed tutorial code instead of performing each step. After loading the completed tutorial code into the workspace, you can run the code as if you performed each step in the tutorial. However, in order to fully attain the learning objectives, it is recommended that you perform the tutorial step by step.
Skill level
Advanced
Audience
This tutorial is intended for WebSphere Commerce store developers who are responsible for modifying existing entity beans.
Prerequisites
Knowledge prerequisitesBefore starting this tutorial you should have a basic understanding of:
- Rational Application Developer.
- The Java programming language.
- Enterprise beans.
Code prerequisitesIf you completed other WebSphere Commerce programming tutorials, there is no harm in leaving the code in the workspace, as it will not conflict with this tutorial.
- Before starting this tutorial, have published a store based upon the consumer direct sample storewithin the development environment. Within this store, be able to complete a purchase (for example, browse the catalog, add items to the shopping cart, check out and see the order confirmation).
- In order to complete the deployment steps, the store must also exist on the target WebSphere Commerce Server.
- In the Enterprise Explorer view, ensure the Toggle Project Grouping button is selected as shown in the following screen capture:
By selecting the Toggle Project Grouping button, you ensure that the view in WebSphere Commerce Developer matches the screen captures and instructions in this tutorial.
Lessons in this tutorial
- Submit orders for testing
This step ensures that when an order is placed, its status is available and accurate. It also ensures that the orders are properly displayed and sorted in the store.
- Import the Order bean
In this step we will import the Order-OrderCaptureData.jar file into Rational Application Developer. The Order-OrderCaptureData.jar file contains the Order bean to which we will add a new finder.
- Modify the Java build paths
The Order-OrderCaptureData project requires the WebSphereCommerceServerExtensionsData project in its Java build path to compile properly. Also, the WebSphereCommerceServerExtensionsLogic project requires the Order-OrderCaptureData project in its Java build path to be able to access its methods.
- Create the new finder
In this step we will create a new finder with an SQL query to find a customer's orders and sort the orders by the time the order was placed. The TIMEPLACED column in the ORDERS table holds this information.
- Generate deploy code and regenerate the OrderAccessBean
In this step, you generate deploy code and regenerate the OrderAccessBean so that the new finder method is added to the OrderAccessBean.
- Extend the Orders data bean
This section explains how to Extend the Orders data bean.
- Modify a JSP file to use the new finder
In this step we will modify the OrderStatusTableDisplay.jsp JSP file to call the getOrdersByTimePlaced method in the ExtendedOrderListDataBean. You will modify the JSP file to change the sorting order of the list of orders that were already processed.
- Test the new finder
Test the finder to ensure that it is working properly.
- Deploy the new code to a target server
In this step we will deploy the changes to a target WebSphere Commerce server by exporting the code from Rational Application Developer, moving the code to the target machine and using WebSphere Application Server to deploy the changes.