Jpa-architecture
提供:Dev Guides
JPA-アーキテクチャ
Java Persistence APIは、ビジネスエンティティをリレーショナルエンティティとして保存するソースです。 PLAIN OLD JAVA OBJECT(POJO)をエンティティとして定義する方法と、関係を持つエンティティを管理する方法を示します。
クラスレベルのアーキテクチャ
次の図は、JPAのクラスレベルのアーキテクチャを示しています。 JPAのコアクラスとインターフェースを示しています。
次の表は、上記のアーキテクチャに示されている各ユニットについて説明しています。
Units | Description |
---|---|
EntityManagerFactory | This is a factory class of EntityManager. It creates and manages multiple EntityManager instances. |
EntityManager | It is an Interface, it manages the persistence operations on objects. It works like factory for Query instance. |
Entity | Entities are the persistence objects, stores as records in the database. |
EntityTransaction | It has one-to-one relationship with EntityManager. For each EntityManager, operations are maintained by EntityTransaction class. |
Persistence | This class contain static methods to obtain EntityManagerFactory instance. |
Query | This interface is implemented by each JPA vendor to obtain relational objects that meet the criteria. |
上記のクラスとインターフェースは、エンティティをレコードとしてデータベースに保存するために使用されます。 データベースにデータを保存するためのコードを書く手間を減らして、クラスをデータベーステーブルにマッピングするためのコードを書くなど、より重要なアクティビティに集中できるようにすることで、プログラマを支援します。
JPAクラスの関係
上記のアーキテクチャでは、クラスとインターフェイスの関係はjavax.persistenceパッケージに属します。 次の図は、それらの関係を示しています。
- EntityManagerFactoryとEntityManagerの関係は* 1対多*です。 EntityManagerインスタンスへのファクトリクラスです。
- EntityManagerとEntityTransactionの関係は 1対1 です。 EntityManager操作ごとに、EntityTransactionインスタンスがあります。
- EntityManagerとQueryの関係は* 1対多*です。 1つのEntityManagerインスタンスを使用して、多数のクエリを実行できます。
- EntityManagerとEntityの関係は* 1対多*です。 1つのEntityManagerインスタンスで複数のエンティティを管理できます。