售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Java Hibernate Cookbook
Table of Contents
Java Hibernate Cookbook
Credits
About the Authors
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why Subscribe?
Free Access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Sections
Getting ready
How to do it…
How it works…
There's more…
See also
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Setting Up Hibernate
Introduction
Getting the required libraries for hibernate
Manually downloading
How to do it…
Using Maven
How to do it…
Creating a hibernate persistent class
Getting ready
How to do it...
There's more…
Providing an XML-based hibernate mapping
How to do it…
How it works…
There's more…
Providing an annotation-based hibernate mapping
How to do it…
How it works…
Declaring a class — Table for the database
Declaring an ID — The primary key for the table
Referencing an object
There's more…
Providing a hibernate configuration using an XML file
How to do it...
How it works...
There's more…
Providing a hibernate configuration using the properties file
How to do it…
How it works…
Configuring hibernate programmatically
How to do it…
How it works…
2. Understanding the Fundamentals
Introduction
Building a SessionFactory
How to do it…
How it works…
There's more…
Creating a generic SessionFactory provider class
How to do it…
How it works…
Opening a new session
Getting ready
How to do it…
How it works…
There's more…
Opening a stateless session
How to do it…
Saving an object to the database
How to do it…
How it works…
There's more…
Fetching an object from the database
How to do it…
How it works…
There's more…
Scenario 1
Code for scenario 1
Output for scenario 1
Explanation for scenario 1
Scenario 2
Code for scenario 2
Output for scenario 2
Explanation for scenario 2
Scenario 3
Code for scenario 3
Output for scenario 3
Explanation for scenario 3
Removing an object from the database
How to do it…
Code
Output
How it works…
Updating an object
How to do it…
Code
Output
How it works…
There's more...
Creating a criteria
How to do it...
Code
Output
How it works…
Restricting the results using a criteria
How to do it…
Code
Output
How it works…
Pagination using a criteria
How to do it...
Code
Output
How it works…
Sorting the results
How to do it…
Code
Output
How it works…
Transforming a result
How to do it...
Scenario 1: Converting a result to List
Scenario 2: Converting a result to Map
Code
Output
Scenario 3: Converting a result to user-defined Bean
Code
Output
Using basic projection
How to do it...
Scenario 1:
Code
Output
Scenario 2:
Code
Output
3. Basic Annotations
Introduction
Declaring a class as an entity and creating a table in the database – @Entity and @Table
How to do it…
How it works…
Creating a column in the table – @Column
How to do it…
There's more…
length
nullable
unique
columnDefinition
scale and precision
insertable and updatable
See also…
Creating a primary key and composite primary key column – @Id and @IdClass
How to do it…
Creating an autogenerator column
How to do it…
Default generation strategy
Sequence generator
Table generator
There's more…
Attributes available in the @GeneratedValue annotation
Strategy
Generator
Attributes available in @TableGenerator annotation
name
table
pkColumnName
valueColumnName
pkColumnValue
initialValue
allocationSize
4. Working with Collections
Introduction
Persisting List
Getting ready
Creating tables
Creating a class
How to do it…
Inserting a record
Code
Output
Retrieving a record
Code
Output
Updating a record
Code
Output
Deleting a record
Code
Output
How it works…
There's more…
Creating classes
Creating tables
Inserting a record
Code
Output
Retrieving a record
Code
Output
Persisting Set
Getting ready
Creating a class
How to do it…
Inserting a record
Code
Output
Retrieving a record
Code
Output
Updating a record
Code
Output
Deleting a record
Code
Output
How it works…
Persisting Map
Getting ready
Creating tables
Creating a class
How to do it…
Inserting a record
Code
Output
Retrieving a record
Code
Output
Updating a record
Code
Output
Deleting a record
Code
Output
How it works…
Persisting Array
Getting ready
How to do it…
Inserting a record
Code
Output
Retrieving a record
Code
Output
5. Working with Associations
Introduction
One-to-one mapping using foreign key association
Getting ready
Creating the tables
Creating the classes
How to do it…
Inserting a record
Code
Output
How it works...
There's more…
Creating the tables
Creating the classes
Inserting a record
Code
Output
Retrieving a record using the parent record
Code
Output
Retrieving a record using the child record
Code
Output
One-to-one mapping using a common join table
Getting ready
Creating the tables
Creating the classes
How to do it…
Inserting a record
Code
Output
How it works…
One-to-one mapping using a common primary key
Getting ready
Creating the tables
Creating the classes
How to do it…
Inserting a record
Code
Output
How it works…
One-to-many mapping or many-to-one mapping
Getting ready
Creating the tables
Creating the classes
How to do it…
Inserting a record
Code
Output
Retrieving a record – many-to-one-mapping
Code
Output
Retrieving a record – one-to-many-mapping
Code
Output
How it works…
Many-to-many mapping
Getting ready
Creating the tables
Creating the classes
How to do it…
Inserting a record
Code
Output
Retrieving a record using Developer with Technology
Code
Output
Retrieving a record using Technology with Developers
Code
Output
How it works…
6. Querying
Introduction
Working with an alias
How to do it…
How it works…
There's more…
Performing aggregate operations
Getting ready
Creating the tables
Creating the classes
Inserting data in the tables
How to do it…
Sum
Code
Output
Avg
Code
Output
Min
Code
Output
Max
Code
Output
Count
Code
Output
Executing a subquery using a criteria
How to do it…
Code
Output
How it works…
Executing a native SQL query
How to do it…
Scalar queries
Code
Output
Entity queries
Code
Output
Executing a query using HQL
How to do it…
The FROM clause
Code
Output
Code
Output
The SELECT clause
Code
Output
How it works…
There's more…
The WHERE clause
The ORDER BY clause
The GROUP BY clause
Using formula in hibernate
How to do it…
Code
Output
How it works…
There's more…
Code
Output
Working with NamedQuery
How to do it…
name
query
Code
Output
There's more…
7. Advanced Concepts
Introduction
Working with a first-level cache
Getting ready
Creating the classes
Creating the tables
How to do it…
Code
Output
How it works…
There's more…
evict (Object object)
Code
Output
clear()
Code
Output
Working with a second-level cache
Getting ready
Enabling a second-level cache
Adding a caching strategy using a POJO class
How to do it…
Code
Output
How it works…
Working with a query cache
Getting ready
Enabling a query cache:
How to do it…
How it works…
There's more...
Code
Output
Working with the table per class hierarchy strategy of inheritance
Getting ready
Creating the classes
Creating the tables
Annotations used in Employee.java
Annotations used in ContractualEmployee.java
Annotations used in PermanentEmployee.java
How to do it…
Code
Output
How it works…
Working with the table per subclass strategy of inheritance
Getting ready
Creating the classes
Creating the tables
How to do it…
Code
Output
How it works…
Working with the table per concrete class strategy of inheritance
Getting ready
Creating the classes
Creating the tables
Annotations used in Employee.java
Annotations used in PermanentEmployee.java and ContractualEmployee.java
How to do it…
Code
Output
How it works…
Working with the versioning of objects
Getting ready
Creating the classes
Creating the tables
How to do it…
Code
Output
How it works…
Code
Output
Maintaining the history of an object
Getting ready
Creating the classes
Creating the tables
How to do it…
Code
Output
How it works…
There's more…
Changing the suffix by changing the property in the configuration file
Changing the prefix by changing the property in the configuration file
Renaming the REV column
Renaming the REVTYPE column
Working with an interceptor
Getting ready
Creating the classes
Creating the tables
How to do it…
Code
Output:
How it works…
The working of InterceptorTest.java
The working of CustomInterceptor.java
The working of onSave Method
The working of preFlush Method
The working of postFlush Method
Working with batch processing
Getting ready
Creating the classes
How to do it…
How it works…
8. Integration with Other Frameworks
Introduction
Integration with Spring
Getting ready
The project dependencies
Creating the tables
Creating a model class
Creating an interface – DAO
The Spring configuration
Reviewing the project structure
How to do it…
The DAO implementations
Code
Output
How it works…
Integration with Struts
Getting ready
The project dependencies
The hibernate configuration
Creating the tables
Creating a model class
Creating an interface – DAO
The Struts configuration
The deployment descriptor
Creating an Action class
The Struts Action mapping
Reviewing the project structure
How to do it…
Implementing a DAO
Creating view – JSP
How it works…
See also…
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜