Home arrow Java arrow Adding Hibernate to a Java Application
JAVA

Adding Hibernate to a Java Application


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).

Author Info:
By: O'Reilly Media
Rating: 5 stars5 stars5 stars5 stars5 stars / 13
November 30, 2006
TABLE OF CONTENTS:
  1. · Adding Hibernate to a Java Application
  2. · Hibernate Mappings for Existing Domain Objects
  3. · Changing the Application Configuration
  4. · Springís Built-In Hibernate Support

print this article
SEARCH DEVARTICLES

Adding Hibernate to a Java Application
(Page 1 of 4 )

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.


blog comments powered by Disqus
JAVA ARTICLES

- Java Too Insecure, Says Microsoft Researcher
- Google Beats Oracle in Java Ruling
- Deploying Multiple Java Applets as One
- Deploying Java Applets
- Understanding Deployment Frameworks
- Database Programming in Java Using JDBC
- Extension Interfaces and SAX
- Entities, Handlers and SAX
- Advanced SAX
- Conversions and Java Print Streams
- Formatters and Java Print Streams
- Java Print Streams
- Wildcards, Arrays, and Generics in Java
- Wildcards and Generic Methods in Java
- Finishing the Project: Java Web Development ...

Watch our Tech Videos 
Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 

Developer Shed Affiliates

 




© 2003-2017 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials