Home > Store

Hibernate: A J2EE Developer's Guide

Register your product to gain access to bonus material or receive a coupon.

Hibernate: A J2EE Developer's Guide

Book

  • Sorry, this book is no longer in print.
Not for Sale

About

Features

A hands-on practical guide to the now most popular object/relational mapping solution for Java.

° Over 333,000 downloads of Hibernate so far (avg 23,000 a month in 2004)

° Teaches pratical solutions with real-life case studies and provides guidance and best practices for developers

° Complete coverage on how to work with other open source tools such as Ant

Description

  • Copyright 2005
  • Edition: 1st
  • Book
  • ISBN-10: 0-321-26819-9
  • ISBN-13: 978-0-321-26819-8

Hibernate is a popular open source object/relational persistence and querysystem and an alternative to Enterprise Java Beans. Compared to EJB,Hibernate is less complex, more easily portable and more powerful for linkingJava with traditional relational databases. Hibernate supports many relationaldatabases including: DB2, Informix, MySQL, Oracle, SAP DB, SQL Server,Sybase, and is downloaded over 23,000 times a month on average in 2004. Thisbook provides J2EE developers with a pratical hands-on guide to working withHibernate and their existing databases. Through numerous code examples andcase studies, the author helps reinforce what Hibernate is and how to use it.

Downloads

Source Code

Download the source code from the author's web site.

Sample Content

Online Sample Chapters

Gathering Performance Metrics for Hibernate

Improving Hibernate's Performance

J2EE Schema Management with Hibernate

Schema Management in Hibernate

Downloadable Sample Chapter

Download the Chapter 10 and Chapter 11 related to this title.

Table of Contents

1. Overview.

    Why Object/Relational Mapping?

    What Is Hibernate?

    Comparing JDBC to Hibernate.

    Hibernate's Mapping System.

    Other Java/Database Integration Solutions.

      Enterprise JavaBeans (EJB) 2.X.

      Enterprise JavaBeans (EJB) 3.0.

      Java Data Objects (JDO).

      Other Commercial O/R Tools.

    How to Obtain and Install.

    Hibernate Distribution.

    Hibernate Extensions Distribution.

    Configuration.

      Supported Databases.

    Introduction to MySQL.

2. Getting Oriented.

    Application Architecture.

    Mapping Files.

      Mapping Files in Depth.

    Generating Java Source.

      Generated Persistent Classes.

    Application Configuration.

      Generated Database Schema.

    Web Application.

    JSP Interface.

      List Posts.

      Create Author.

      List Authors.

      Edit Author.

      Create Post.

      View Post.

      Edit Post.

      Delete Post.

      Delete Author.

      Next Steps.

3. Starting from Java.

    Java Object Model.

      Java Classes.

      Working with Xdoclet.

    Generated Mapping Files.

    Generated Schema.

    Working with Artifacts and Owners.

4. Starting from an Existing Schema.

    Initial Schema.

    Using Middlegen.

      Obtaining Middlegen.

      Configuring Middlegen.

      Running Middlegen.

    Generated Mapping Files.

    Generated Java.

    Working with the Database.

5. Mapping Files.

    Basic Structure.

    Mapping File Reference.

      any.

      array.

      bag.

      cache.

      class.

      collection-id.

      column.

      component.

      composite-element.

      composite-id.

      composite-index.

      discriminator.

      dynamic-component.

      element.

      generator.

      hibernate-mapping.

      id.

      idbag.

      import   -.

      index.

      index-many-to-any.

      index-many-to-many.

      joined-subclass.

      key.

      key-many-to-one.

      key-property.

      list.

      many-to-any.

      many-to-many.

      many-to-one.

      map.

      meta.

       meta-value.

      nested-composite-element.

      one-to-many.

      one-to-one.

      param.

      parent.

      primitive-array.

      property.

      query.

      return.

      set.

      sql-query.

      subclass.

      synchronize.

      timestamp.

      version.

6. Persistent Objects.

    Sessions.

      Setting up the Configuration.

      Obtaining the Session.

      Creating Objects.

      Finding Objects.

      Refreshing Objects.

      Deleting Objects.

      Updating Objects.

     Objects and Identity.

      What Is Identity?

      Identity within a Session.

      Generating Identity (Primary Keys).

      Built-In Hibernate Generators.

      Composite Identity.

      Unsaved Value.

    Life-Cycle Methods.

7. Relationships.

    Database Relationships.

      Many-to-One.

      One-to-Many.

      Many-to-Many.

      One-to-One.

    Java Collection Relationships.

    Java Class Relationships.

      Subclasses.

      Joined Subclasses.

      Components.

    Any-Based Relationships.

    Bi-directional Relationships.

8. Queries.

    HQL.

      Using Hibern8 IDE.

    HQL Reference.

      Notation Reference.

    Select.

      Selected Properties List.

      Aggregate.

      Collection Properties.

    From.

      Join Types.

    Where.

      Logical Operations.

      Boolean Operations.

      Quantified Expression.

      Parameter Binding.

    Group By.

    Having.

    Order By.

    Criteria Queries.

      Method Chaining.

      Easily Override Lazy Settings.

    Native SQL Queries.

9. Transactions.

    Introduction to Transactions.

      Sessions, Transactions, and Flushing.

    Optimistic and Pessimistic Locking.

      Pessimistic Locks.

      Optimistic Locks.

10. Performance.

    Finding and Solving Problems.

      IronTrack SQL.

    Queries.

      Lazy Objects.

      Collections.

    Inserts.

    Connection Pooling.

    Caching.

      Understanding Caches.

      Configuring a Cache.

      Standard Caches.

      Using a Custom Cache.

11. Schema Management.

    Updating an Existing Schema.

      Schema Updates from within an Application.

      Command Line Schema Updates.

      Ant Task Schema Updates.

    Generating Update and Drop Scripts.

      Command-Line Script Generation.

      Ant Task Script Generation.

      Generating Multiple Scripts.

12. Best Practices, Style Guide, Tips and Tricks.

    Reducing Code with Inversion of Control.

    Reducing Session Creation Impact with ThreadLocal.

    Using Hibernate as an EJB BMP Solution.

    Integrating with Other Technologies.

    Applications That Use Hibernate.

    Strategies for Getting Started.

      Where to Start?

      Start with Many-to-One and One-to-Many.

      Profile Database Fetching.

13. Future Directions.

    Hibernate 3.0.

    EJB 3.0.

    Here and Now.

Index.

Preface

Untitled Document I got into Hibernate because I'm lazy. Specifically, I got tired of writing my own systems to bridge my Java applications and relational databases. I write both Swing and server-based applications; I can't assume (nor do I enjoy) the complexity of EJB container-managed persistence. I hate writing SQL when all I really want to do is write Java code. I really don't like writing endless pages of mindless code, loading my JDBC results into Java objects and back.

Simply put, Hibernate solves all of these problems for me, and it does so in a fast, flexible manner. I can use it with Swing, JSP, or as an EJB BMP solution. I can test my code outside of a container. I can even use it to manage my database schema.

Regardless of your background—whether you are a nothing-but-JDBC developer or a full EJB-level architect—you can save yourself considerable time and effort by adding Hibernate to your skill set, and in the process you can get a significant leg up on learning EJB 3.0. You can learn the principal terminology and concepts behind EJB 3.0 today, on the Java 2 (JDK 1.4) JVM you are using now.

Life is short. Spend less time writing code that bridges your database and your Java application and more time adding new features.

Required Skills Familiarity with Java development, including object-oriented design. If you don't already know Java, this book will be quite unhelpful.

Familiarity with SQL and relational databases. There are many books on both the practical and theoretical sides of relational database design and development. The examples in this book are all done with MySQL, a free, open-source database. If you have never worked with a relational database before, you will almost certainly want to pick up an introductory text on MySQL.

Familiarity with Ant. Many books on Ant are available; if you are a Java developer and haven't already worked with Ant, you should learn.

Other skills, such as familiarity with JSP web application development, are helpful but not required. One example in Chapter 2 assumes the use of a web server such as Tomcat—all other examples can be run from the command-line.

Roadmap This book can be loosely broken into a few basic sections. Following the introductory chapter, Chapters 2 through 4 illustrate different approaches to Hibernate development: starting from a Hibernate object/relational mapping file, starting from Java code, or starting from an existing database schema. Chapters 5 through 12 cover basic concepts and the use of persistent objects, concluding with chapters on tools, performance, and best practices. Chapter 13 discusses the future of Hibernate.

This book can be read in several ways, depending on your inclination. If you wish to start with real-world examples and then move into general usage and theory, you can more or less read the book in order. If you prefer a higher-level introduction, you may wish to start with Chapters 6 through 9 and then return to the beginning. Regardless of the method you choose, I encourage you to download and work through the examples from http://www.cascadetg.com/hibernate/.

Chapter 1 introduces Hibernate. It compares Hibernate to other forms of database access, including JDBC and a variety of other tools. It concludes with a list of required files and where to obtain them.

Chapter 2 illustrates an example of development starting with a Hibernate mapping file. The mapping file is used to generate Java and database schema files.

Chapter 3 shows how to use Hibernate when starting from a Java source file. XDoclet is used to generate the mapping file, and Hibernate is used to generate the database schema.

Chapter 4 shows how to use Middlegen in conjunction with Hibernate when starting from an existing database schema.

Chapter 5 is a reference to the Hibernate mapping file format. While few readers will want to read this chapter from start to finish, this reference will hopefully prove invaluable on a day-to-day basis when using Hibernate.

Chapter 6 contains information on the general use of Hibernate, including basic operations such as creating, finding, refreshing, updating, and deleting objects.

Chapter 7 explains how Hibernate handles both class and database relationship concepts.

Chapter 8 discusses Hibernate's two main query mechanisms, HQL and Criteria, and also shows how native SQL can be integrated.

Chapter 9 covers the various aspects of a Hibernate transaction, illustrating both session and database transaction concepts.

Chapter 10 shows tools for identifying potential Hibernate performance issues.

Chapter 11 discusses how Hibernate can be used to manage an application's schema.

Chapter 12 covers various Hibernate best practices.

Chapter 13 discusses future directions for Hibernate, and also covers potential similarities with EJB 3.0.

Index

Download the Index file related to this title.

Updates

Submit Errata

More Information

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.

Overview


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information


To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.

Surveys

Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.

Newsletters

If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information


Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.

Security


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.

Children


This site is not directed to children under the age of 13.

Marketing


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information


If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.

Choice/Opt-out


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information


Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents


California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure


Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.

Links


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact


Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice


We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020