CHAPTER 9 n SEARCHES AND (Web design templates) QUERIES 199 n

CHAPTER 9 n SEARCHES AND QUERIES 199 n SEARCHES AND QUERIES 199 The Software class, shown in Listing 9-3, extends the Product class and adds a version property we added this subclass so that we could demonstrate polymorphism with Hibernate s queries. Listing 9-3. The Software Class package com.hibernatebook.queries; public class Software extends Product { private String version; public Software() { } public Software(String name, String description, double price, String version) { super(name, description, price); this.setVersion(version); } public String getVersion() { return version; } public void setVersion(String version) { this.version = version; } } The Hibernate mapping files for these three classes are in the source directory for the book, along with a test harness for populating the database and running the examples in this chapter and the next. The first example executes our HQL statement, from Product, and then retrieves a List of Product objects. Query query = session.createQuery(”from Product”); List results = query.list(); Many of the other examples in this chapter use the same supporting Java code as this example. We are going to provide just the HQL for these examples you can execute them the same way we did here, substituting that HQL for the from Product HQL statement. This should make each example clearer as to what you should be looking at. You could also execute these HQL statements in the Hibernate Tools scratch pad.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

Leave a Reply