什么是持久性语境? [英] What is Persistence Context?
问题描述
我是Java世界和JPA的新手。我正在研究JPA,并遇到了许多新的术语,如实体,持久性。在阅读时,我无法理解持久性上下文的确切定义。
任何人都可以用简单的非专业术语来解释它吗?它与 @Entity
中使用的数据有什么关系?
例如,我也发现了这个定义难以理解:
持久化上下文是一组实体,对于任何持久性身份,都有一个唯一的实体实例。
持久化上下文处理一组实体,这些实体将数据保存在某个持久性存储中(例如一个数据库)。特别是,上下文知道实体与上下文和底层持久性存储相关的不同状态(例如托管,分离)。
尽管Hibernate相关(JPA提供商),我认为这些链接很有用:
http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch03.html
http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/architecture.html
在Java EE中,持久化上下文通常通过EntityManager访问。
http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html
<各种各样的一个实体可以拥有的状态,以及它们之间的转换如下所述:
http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/objectstate.html
http:/ /gerrydevstory.com/wp-content/uploads/2012/05/jpa-state-transtition.png
I am new to the Java world and JPA. I was studying JPA and came across many new terms like Entity, persistence. While reading, I could not understand the exact definition for Persistence Context.
Can anyone explain it in simple laymen terms? What is it to do with the data used in the @Entity
?
For example, I find this definition too complicated to understand:
A persistence context is a set of entities such that for any persistent identity there is a unique entity instance.
A persistence context handles a set of entities which hold data to be persisted in some persistence store (e.g. a database). In particular, the context is aware of the different states an entity can have (e.g. managed, detached) in relation to both the context and the underlying persistence store.
Although Hibernate-related (a JPA provider), I think these links are useful:
http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch03.html
http://docs.jboss.org/hibernate/entitymanager/3.5/reference/en/html/architecture.html
In Java EE, a persistence context is normally accessed via an EntityManager.
http://docs.oracle.com/javaee/6/api/javax/persistence/EntityManager.html
The various states an entity can have and the transitions between these are described below:
http://docs.jboss.org/hibernate/entitymanager/3.6/reference/en/html/objectstate.html
http://gerrydevstory.com/wp-content/uploads/2012/05/jpa-state-transtition.png
这篇关于什么是持久性语境?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!