The document provides an introduction to Hibernate and demonstrates a basic "Hello World" example using Hibernate. It shows how to define a persistent class, save and retrieve data from the database using Hibernate, and configure Hibernate via properties files or XML. Key aspects of the Hibernate architecture like the SessionFactory, Session, and Transactions are also explained at a high level.
16. SessionFactory SessionFactory (org.hibernate.SessionFactory) A thread safe (immutable) cache of compiled mappings for a single database. A factory for Session and a client of Connection Provider. Might hold an optional (second-level) cache of data that is reusable between transactions, at a process- or cluster-level.
17. Session Session (org.hibernate.Session) A single-threaded, short-lived object representing a conversation between the application and the persistent store. Wraps a JDBC connection. Factory for Transaction. Holds a mandatory (first-level) cache of persistent objects, used when navigating the object graph or looking up objects by identifier.
18. Persistent Objects and Collections Persistent objects and collections Short-lived, single threaded objects containing persistent state and business function. These might be ordinary JavaBeans/POJOs, the only special thing about them is that they are currently associated with (exactly one) Session. As soon as the Session is closed, they will be detached and free to use in any application layer (e.g. directly as data transfer objects to and from presentation).
19. Transient and detached objects and collections Transient and detached objects and collections Instances of persistent classes that are not currently associated with a Session. They may have been instantiated by the application and not (yet) persisted or they may have been instantiated by a closed Session. .
20. Transaction Transaction (org.hibernate.Transaction) (Optional) A single-threaded, short-lived object used by the application to specify atomic units of work. Abstracts application from underlying JDBC, JTA or CORBA transaction. A Session might span several Transactions in some cases. However, transaction demarcation, either using the underlying API or Transaction, is never optional! .
21. ConnectionProvider ConnectionProvider (org.hibernate.connection.ConnectionProvider) (Optional) A factory for (and pool of) JDBC connections. Abstracts application from underlying Datasource or DriverManager. Not exposed to application, but can be extended/implemented by the developer.
22. TransactionFactory TransactionFactory (org.hibernate.TransactionFactory) (Optional) A factory for Transaction instances. Not exposed to the application, but can be extended/implemented by the developer.
23. Extension Interfaces Extension Interfaces Hibernate offers many optional extension interfaces you can implement to customize the behavior of your persistence layer.(Ex. Primary key generation,SQL Dialet , Caching,JDBC connection, Proxy creationetc., Given a "lite" architecture, the application bypasses the Transaction/TransactionFactory and/or ConnectionProvider APIs to talk to JTA or JDBC directly.
24. Instance States Instance states An instance of a persistent classes may be in one of three different states, which are defined with respect to a persistence context .
25. Instance States Instance states An instance of a persistent classes may be in one of three different states, which are defined with respect to a persistence context .
26. Instance States Transient The instance is not, and has never been associated with any persistence context. It has no persistent identity (primary key value).
27. Instance States Persistent The instance is currently associated with a persistence context. It has a persistent identity (primary key value) and, perhaps, a corresponding row in the database. For a particular persistence context, Hibernate guarantees that persistent identity is equivalent to Java identity (in-memory location of the object).
28. Instance States Detached The instance was once associated with a persistence context, but that context was closed, or the instance was serialized to another process. It has a persistent identity and, perhaps, a corresponding row in the database. For detached instances, Hibernate makes no guarantees about the relationship between persistent identity and Java identity.
38. XDoclet - @hibernate.id tag The default size for the field type. Specified the size of the database column length Null. If we use a String or Long as the primary key, you don’t need to specify this.Specify the unsaved-value=0 for primitive types. Contains a value that will distinguish transient instances from persistent ones unsaved-value The property name Contains the name of the column column The return type of the field. Specifies the Hibernate type for this field type None. native will work for most databases Contains the key generation that Hibernate will use to insert new instances generator-class Default Description Attribute
39. The @hibernate.property tag Return type of the field Specifies the hibernate type type false Specifies that a unique constraint should be enforced unique false Specifies that a not-null constraint should be enforced not-null The default length for a field. Specifies the column size length The name of the field Contains the name of the column column Default Description Attribute
40. The @hibernate.column tag The type implied by the length Specifies database-specific column type, like TEXT or LONGBLOG sql-type No constraint created Creates a uniquely named constraint with this name unique-key No named index created Contains the name of a table index for this column index false Specifies that a unique constraint should be enforced unique False Specifies that a not-null constraint should be enforced not-null The default length for a field. Specifies the column size length It’s mandatory, so no default Contains the name of the column this property maps to name Default Description Attribute
41. The @hibernate.many-to-one attributes None. Acceptable values include all, none,save-update or delete Specifies how cascading operations should be handled from parent to child Cascade false Specifies that a unique constraint should be enforced Unique False Specifies that a not-null constraint should be enforced not-null The class of the field Contains the associated persistent class Class The name of the field Contains the name of the column in the database column Default Description Attribute
42. Hibernate mapping elements to XDoclet tags @hibernate.collection-one-to-many A nested <one-to-many> @hibernate.collection-key A nested <key /> @hibernate.set <set / > XDoclet tag Mapping element
43. The @hibernate.set tag false Specifies whether the collection is inverse(determines which end of the collection is the parent) Inverse No ORDERBY added Specifies whether the query to fetch the collection should ad a SQL ORDER BY(asc/desc) Order-by None. Acceptable values include all, none,save-update or delete Specifies how cascading operations should be handled from parent to child Cascade Not sorted by default Specifies whether the collection should be sorted in memory. Sort False Specifies whether the collection should be lazily initialized Lazy For a many-to-many, it uses the name of the field For the man-to-many association only,contains the association table name for joins Table None. Acceptable values include all,none,save-update, all-delete-orphan and delete Specifies how cascading operations should be handled from parent to child Cascade Default Description Attribute