Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Save to My Library
Look up keyword
Like this
1Activity
0 of .
Results for:
No results containing your search query
P. 1
Hibernate Reference

Hibernate Reference

Ratings: (0)|Views: 54 |Likes:
Published by api-3712164

More info:

Published by: api-3712164 on Oct 15, 2008
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

03/18/2014

pdf

text

original

Hibernate Reference Documentation
Version: 3.0.3
Table of Contents
Preface.......................................................................................................................................... viii
1. Quickstart with Tomcat..............................................................................................................1

1.1. Getting started with Hibernate............................................................................................. 1 1.2. First persistent class........................................................................................................... 3 1.3. Mapping the cat................................................................................................................. 4 1.4. Playing with cats................................................................................................................ 5 1.5. Finally............................................................................................................................... 7

2. Introduction to Hibernate...........................................................................................................8

2.1. Preface.............................................................................................................................. 8
2.2. Part 1 - The first Hibernate Application............................................................................... 8
2.2.1. The first class.......................................................................................................... 8
2.2.2. The mapping file..................................................................................................... 9
2.2.3. Hibernate configuration......................................................................................... 11
2.2.4. Building with Ant.................................................................................................. 12
2.2.5. Startup and helpers................................................................................................ 13
2.2.6. Loading and storing objects.................................................................................... 15
2.3. Part 2 - Mapping associations............................................................................................ 17
2.3.1. Mapping the Person class....................................................................................... 17
2.3.2. A unidirectional Set-based association.................................................................... 17
2.3.3. Working the association......................................................................................... 19
2.3.4. Collection of values............................................................................................... 20
2.3.5. Bi-directional associations..................................................................................... 21
2.3.6. Working bi-directional links................................................................................... 21
2.4. Summary......................................................................................................................... 22

3. Architecture..............................................................................................................................23

3.1. Overview......................................................................................................................... 23 3.2. Instance states.................................................................................................................. 25 3.3. JMX Integration............................................................................................................... 25 3.4. JCA Support.................................................................................................................... 26

4. Configuration............................................................................................................................27

4.1. Programmatic configuration.............................................................................................. 27
4.2. Obtaining a SessionFactory............................................................................................... 27
4.3. JDBC connections............................................................................................................ 28
4.4. Optional configuration properties...................................................................................... 29
4.4.1. SQL Dialects......................................................................................................... 34
4.4.2. Outer Join Fetching............................................................................................... 35
4.4.3. Binary Streams...................................................................................................... 35
4.4.4. Second-level and query cache................................................................................. 35
4.4.5. Query Language Substitution................................................................................. 36
4.4.6. Hibernate statistics................................................................................................ 36
4.5. Logging........................................................................................................................... 36
4.6. Implementing a NamingStrategy....................................................................................... 37
4.7. XML configuration file..................................................................................................... 37
4.8. J2EE Application Server integration.................................................................................. 38
4.8.1. Transaction strategy configuration.......................................................................... 39
4.8.2. JNDI-bound SessionFactory................................................................................... 40
4.8.3. Automatic JTA and Session binding....................................................................... 40
4.8.4. JMX deployment................................................................................................... 40

Hibernate 3.0.3
ii
5. Persistent Classes......................................................................................................................42

5.1. A simple POJO example................................................................................................... 42
5.1.1. Declare accessors and mutators for persistent fields................................................. 43
5.1.2. Implement a no-argument constructor..................................................................... 43
5.1.3. Provide an identifier property (optional).................................................................. 43
5.1.4. Prefer non-final classes (optional)........................................................................... 44
5.2. Implementing inheritance................................................................................................. 44
5.3. Implementing equals() and hashCode().............................................................................. 44
5.4. Dynamic models.............................................................................................................. 45

6. Basic O/R Mapping...................................................................................................................48

6.1. Mapping declaration......................................................................................................... 48
6.1.1. Doctype................................................................................................................ 49
6.1.2. hibernate-mapping................................................................................................. 49
6.1.3. class..................................................................................................................... 50
6.1.4. id.......................................................................................................................... 52
6.1.4.1. Generator................................................................................................... 53
6.1.4.2. Hi/lo algorithm........................................................................................... 54
6.1.4.3. UUID algorithm......................................................................................... 54
6.1.4.4. Identity columns and sequences................................................................... 54
6.1.4.5. Assigned identifiers.................................................................................... 55
6.1.4.6. Primary keys assigned by triggers................................................................ 55
6.1.5. composite-id......................................................................................................... 55
6.1.6. discriminator......................................................................................................... 56
6.1.7. version (optional).................................................................................................. 56
6.1.8. timestamp (optional).............................................................................................. 57
6.1.9. property................................................................................................................ 57
6.1.10. many-to-one........................................................................................................ 59
6.1.11. one-to-one........................................................................................................... 60
6.1.12. component, dynamic-component.......................................................................... 62
6.1.13. properties............................................................................................................ 62
6.1.14. subclass.............................................................................................................. 63
6.1.15. joined-subclass.................................................................................................... 64
6.1.16. union-subclass..................................................................................................... 65
6.1.17. join..................................................................................................................... 66
6.1.18. key..................................................................................................................... 67
6.1.19. column and formula elements............................................................................... 67
6.1.20. import................................................................................................................. 68
6.1.21. any..................................................................................................................... 68
6.2. Hibernate Types............................................................................................................... 69
6.2.1. Entities and values................................................................................................. 69
6.2.2. Basic value types................................................................................................... 70
6.2.3. Custom value types............................................................................................... 71
6.3. SQL quoted identifiers...................................................................................................... 72
6.4. Metadata alternatives........................................................................................................ 72
6.4.1. Using XDoclet markup.......................................................................................... 72
6.4.2. Using JDK 5.0 Annotations.................................................................................... 74

7. Collection Mapping...................................................................................................................75

7.1. Persistent collections........................................................................................................ 75
7.2. Collection mappings......................................................................................................... 75
7.2.1. Collection foreign keys.......................................................................................... 76
7.2.2. Collection elements............................................................................................... 77
7.2.3. Indexed collections................................................................................................ 77

HIBERNATE - Relational Persistence for Idiomatic Java
Hibernate 3.0.3
iii

You're Reading a Free Preview

Download
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->