Hibernate from novice to professional free ebook
Primary Key Mandatory and Unique Constraints Cons of Annotations Choosing Which to Use JPA 2 Persistence Annotations Primary Keys with Id and GeneratedValue Modeling Entity Relationships One Table per Class Hierarchy More Exotic Mappings The any Tag Distinct Results Using a Direct Mapping Downloading the Hibernate Tools Plug-in The Boilerplate Project Configuration Changes to Tools and Libraries Summary He got caught up with the Internet when he got access to a UNIX shell account, and it has been downhill ever since.
Jeff is based in Austin, Texas and helps large companies solve tough problems with content management, search engines, and web application development. Jeff also co-authored Professional Struts. He built his first PC from discarded, faulty, and obsolete components; and he considers that to be the foundation of his career as an integration consultant. Sumit has keen interest in database internals, algorithms, search engine technology, data mining, and machine learning.
Sumit has invented some basic generalized algorithms to find divisibility between numbers and also invented divisibility rules for prime numbers less than Sumit loves to play badminton and swim. He is also an amateur astrophysicist and is incorporating green habits into his daily life.
Jeff and Dave would like to thank the staff of Apress for their consistent good humor in the face of looming deadlines. Particular thanks are due to Debra Kelly, our ever-present project manager, for keeping this book on the rails; and to Patrick Meader, for correcting our dodgy spelling and grammar.
Thanks to Fran Parnell, as well, for managing the project in its early stages. Special thanks to Jonathan Gennick for his contributions and particularly for his help directing the new edition. Thanks also to Steve Anglin for letting us write for Apress and to Sumit Pal for his contributions as technical reviewer.
Finally, thanks are due to the Hibernate team for producing an awesome piece of software. Jeff would like to thank Cheri for putting up with endless late nights to meet chapter deadlines; he would also like to thank Rocky for giving him a reason to put the laptop away on a sunny day. He would also like to thank his friends Roman and Jason for reviewing parts of the book. Hibernate is an amazing piece of software. With a little experience and the power of annotations, you can build a complex, database-backed system with disturbing ease.
Once you have built a system using Hibernate, you will never want to go back to the traditional approaches. While Hibernate is incredibly powerful, it presents a steep learning curve when you first encounter it—steep learning curves are actually a good thing because they impart profound insight once you have scaled them.
Yet gaining that insight takes some perseverance and assistance. Our aim in this book is to help you scale that learning curve by presenting you with the minimal requirements of a discrete Hibernate application, explaining the basis of those requirements, and walking you through an example application built using to them. We then provide additional material to be digested once the fundamentals are firmly understood.
Throughout, we provide examples, rather than relying upon pure discourse. We hope that you will continue to find this book useful as a reference text long after you have become an expert on the subject.
All of our examples use open source software—primarily the Hibernate API itself—so you will not need to purchase any software to get started with Hibernate development.
This book is not an academic text. Our focus is instead on providing extensive examples and taking a pragmatic approach to the technology that it covers. To true newcomers to the Hibernate API, we recommend that you read at least the first three chapters in order before diving into the juicy subjects of later chapters. Very experienced developers or those with experience with tools similar to Hibernate will want to skim through the latter half of the book for interesting chapters.
Readers familiar with Hibernate will want to turn to the appendixes for discussion of more arcane topics. This book is informally divided into three parts. Chapters 1 through 8 describe the fundamentals of Hibernate, including configuration, the creation of mapping files, and the basic APIs.
Chapters 9 through 11 describe the use of queries, criteria, and filters to access the persistent information in more sophisticated ways.
Chapter 12 is a case study that starts with an existing database, and then shows you how to map that database to a Java application using Hibernate. Finally, the appendixes discuss features that you will use less often, or that are peripheral to the core Hibernate functionality. The following list describes more fully the contents of each chapter:. Chapter 1 outlines the purpose of persistence tools and presents excerpts from a simple example application to show how Hibernate can be applied.
It also introduces core terminology and concepts. Chapter 2 discusses the fundamentals of configuring a Hibernate application. It presents the basic architecture of Hibernate and discusses how a Hibernate application is integrated into an application.
Chapter 3 presents the example application from Chapter 1 in its entirety, walking you through the complete process of creating and running the application. It then looks at a slightly more complex example and introduces the notion of generating the database schema directly from Hibernate annotations. Chapter 4 covers the Hibernate life cycle in depth.
It discusses the life cycle in the context of the methods available on the core interfaces. It also introduces key terminology and discusses the need for cascading and lazy loading. Chapter 5 explains why mapping information must be retained by Hibernate and demonstrates the various types of associations that can be represented by a relational database.
It briefly discusses the other information that can be maintained within a Hibernate mapping. Chapter 6 explains how Hibernate lets you use the annotations to represent mapping information. It provides detailed examples for the most important annotations, and discusses the distinctions between the standard JPA 2 annotations and the proprietary Hibernate ones.
Chapter 7 explains how the XML-based mapping files can be used to represent mapping information in Hibernate. It provides examples for all of the most common mapping types and reference notes for the more obscure ones.
Chapter 8 revisits the Hibernate Session object in detail, explaining the various methods that it provides. The chapter also discusses the use of transactions, locking, and caching, as well as how to use Hibernate in a multithreaded environment.
Chapter 9 discusses how Hibernate can be used to make sophisticated queries against the underlying relational database using the built-in Hibernate Query Language HQL.
Chapter 10 introduces the Criteria API, which is a programmatic analog of the query language discussed in Chapter 9. Chapter 11 discusses how the Filter API can be used to restrict the results of the queries introduced in Chapters 9 and Chapter 12 is a case study chapter that illustrates how to use Hibernate with an existing database.
This chapter draws on topics covered in the previous 11 chapters to demonstrate a common use case. Appendix A presents a large number of peripheral features that do not warrant more extensive coverage in a beginner-level text. The chapter discusses the basics, with examples, of the support for versioning and optimistic locking, the provision for persisting and retrieving maps of information, and some of the obscure limitations of Hibernate and various ways that these can be worked around.
It also discusses the use of events and interceptors. The chapter briefly touches on Hibernate Search, which bridges Lucene and Hibernate. Appendix B discusses how the Hibernate Tools toolset can be used to enhance development with the Eclipse development environment and the Ant build tool. It also explains how the Ant code-generation tasks can be customized. The integration of Hibernate as the persistence layer of a Spring application is complex, so we present a working example, including the entire bean definition file, with discussions of the appropriate way to manage the session in the Spring MVC environment.
This chapter also discusses how Spring can enforce the proper transactional boundaries when using Hibernate. Appendix D discusses some topics of interest to developers who are working with a preexisting base of code that was built using version 2 of Hibernate.
We present the various approaches for coexisting with Hibernate 3 code, as well as for migrating a Hibernate 2 code base to the Hibernate 3 API. Please feel free to visit the Apress web site and download all the code from there. We welcome feedback from our readers. If you have any queries or suggestions about this book, or technical questions about Hibernate, or if you just want to share a really good joke, you can e-mail Dave Minter at.
Most significant development projects involve a relational database. The mainstay of most commercial applications is the large-scale storage of ordered information, such as catalogs, customer lists, contract details, published text, and architectural designs. With the advent of the World Wide Web, the demand for databases has increased.
Though they may not know it, the customers of online bookshops and newspapers are using databases. Somewhere in the guts of the application a database is being queried and a response is offered. While the demand for such applications has grown, their creation has not become noticeably simpler. Hibernate 3. We think that Hibernate represents a good first choice, as it does not preclude the simultaneous use of these alternative approaches.
In our ideal world, it would be trivial to take any Java object and persist it to the database. No special coding would be required to achieve this, no performance penalty would ensue, and the result would be totally portable. In this ideal world, we would perhaps perform such an operation in a manner like that shown in Listing There would be no nasty surprises, no additional work to correlate the class with tables in the database, and no performance problems.
This book packs in information about the release of the Hibernate 3. Experienced author Dave Minter and contributor Jeff Linwood provide more in-depth examples than any other books for Hibernate beginners. The authors also present material in a lively, example-based mannernot in a dry, theoretical, hard-to-read fashion.
And since the book keeps its focus on Hibernate without wasting time on nonessential third-party tools, you'll be able to immediately start building transaction-based engines and applications. Develop your coding skills by exploring Java concepts and techniques such as Strings, Objects and Types, …. Learn how to correctly utilize the most popular Object-Relational Mapping tool for your Enterprise application About ….
Over 50 recipes to help you build dynamic and powerful real-time Java Hibernate applications About This …. Skip to main content.
0コメント