Adding Hibernate to a Java Application
(Page 1 of 4 )
This article concludes our discussion covering the addition of a search service to a Java application. It is excerpted from chapter 10 of the book
Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764).
Adding Hibernate
jPetStore uses a relatively straightforward architecture for providing database access. There is an interface layer that provides functional mapping to the DAOs themselves without worrying about actual implementation details. The specific DAOs vary based on the backend database; we’ll be examining the ones targeting HSQLDB (Hypersonic SQL).
Existing Architecture
Let’s look at how the Product class is managed. Product is the domain object that represents one item in the catalog.
Product is the domain object that represents one item in the catalog.class is managed. Product is the domain object that represents one item in the catalog.Product class is managed. Product is the domain object that represents one item in the catalog.Let’s look at how the Product class is managed. Product is the domain object that represents one item in the catalog.
package org.springframework.samples.jpetstore.domain;
import java.io.Serializable;
public class Product implements Serializable {
private String productId;
private String categoryId;
private String name;
private String description;
public String getProductId() { return productId; }
public void setProductId(String productId) { this.productId = productId.trim(); }
public String getCategoryId() { return categoryId; }
public void setCategoryId(String categoryId) { this.categoryId = categoryId; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
public String getDescription() { return description; }
public void setDescription(String description) { this.description = description;}
public String toString() {
return getName();
}
}
Its persistence is managed through an object that implements theProductDaointerface. AProductDao must be able to load a specific product given its ID, or load a list of products either from a category or from a set of keywords.
public interface ProductDao {
List getProductListByCategory(String categoryId) throws DataAccessException;
List searchProductList(String keywords) throws DataAccessException;
Product getProduct(String productId) throws DataAccessException;
}
There currently exists a class calledSqlMapProductDao that looks up product information in Hypersonic SQL through SQL mapping files.
Next: Hibernate Mappings for Existing Domain Objects >>
More Java Articles
More By O'Reilly Media
|
This article is excerpted from the book Better, Faster, Lighter Java, written by Bruce A. Tate and Justin Gehtland (O'Reilly; ISBN: 0596006764). Check it out today at your favorite bookstore. Buy this book now.
|
|