Hibernate architecture

xiaoxiao2021-03-06  42

Chapter 2. Architecture

2.1.

Overview of Hibernate very high-level:

This picture shows Hibernate to use databases and profile data to provide persistence services (and persistent objects) for applications.

Let us observe the runtime architecture more detailed. Very unfortunate, Hibernate is more complicated, providing several different ways of operation. We show two extreme situations. In a lightweight system, the app provides JDBC connections and manages its own business. This approach uses a minimum subset of Hibernate APIs.

In a comprehensive resolution system, for the application, all underlying JDBC / JTA APIs are abstract, Hibernate will take care of all the details.

Here is the definition of some objects in the figure:

SessionFactory (Net.sf.hibernate.SessionFactory)

A thread of the compiled mapping file, a non-variable cache snapshot. It is a session factory. Is a customer of ConnectionProvider.

It may be a cache for data reused between transactions.

Session, session (net.sf.hibernate.Session)

Single thread, short life, represents a dialogue between the application and the persistence layer. Encapsulated a JDBC connection. It is also a factory of Transaction.

Hold a cache for persistent objects.

Persistent Object and Collection

A short life-proof single-threaded object contains persistent status and business features. They may be ordinary Javabeans, the only particular special thing they are now belonging and only belongs to a session.

Temporant Object and Collection

There is currently no example of persistence classes belonging to a session. They may have just been instantiated by programs, have not been reached, or they are instantiated by a closed session.

Transaction (net.sf.hibernate.transaction)

(Optional) Single thread, a short life-proof object, the application uses it to represent a batch of atomic operations. It is an abstraction of the underlying JDBC, JTA or CORBA transaction. A session may span multiple Transaction transactions.

ConnectionProvider (Net.sf.hibernate.Connection.ConnectionProvider)

(Optional) JDBC connection factories and pools. Abstract from the underlying DataSource or DriverManager. Not visible to the application.

TransactionFactory (net.sf.hibernate.transactionFactory)

(Optional) Factory of a transaction instance. Not visible to the application.

In the light structure above, the program does not use Transaction / TransactionFactory or ConnectionProvider API, direct and JTA / JDBC dialogue.

2.2. Persisuse Object Identity

Applications may simultaneously save the same persistent object in two different sessions. However, two session instances are unlikely to share an instance of a persistent class. There are two different methods for identifying whether the object is the same.

Persistent Identity, persistence distinguishing

foo.getid (). Equals (bar.getid ())

JVM Identity, JVM identification

Foo == bar

These two are equivalent to the object returned to the same specific session. However, when the program is parallel to access the "same" (persistent distinguished) business object in two different sessions, the two object instances are "different" (JVM discriminations) from the JVM perspective. Ways parallel access (application does not need to synchronize any business objects, just follow the principles of each session a thread) and object identification (in a session in the application, you can use == to compare the object) The problem left to Hibernate and database.

2.3. JMX integration

JMX is used to manage J2EE standards for Java components. Hibernate can be managed by standard JMX MBean, but most programs have not supported JMX, Hibernate also supports some non-standard configuration.

Check out the Hibernate website, you can get more information about how to configure Hibernate into a JMX component in JBOSS.

2.4. JCA support

Hibernate can also be configured to become a JCA connector. For more details, please refer to the website. This article is taken from: Hibernate Manual

转载请注明原文地址:https://www.9cbs.com/read-61649.html

New Post(0)