什么是持久化上下文? [英] What is Persistence Context?

查看:30
本文介绍了什么是持久化上下文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 Java 世界和 JPA 的新手.我在学习 JPA 时遇到了许多新术语,例如实体、持久性.在阅读时,我无法理解持久上下文的确切定义.

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.

谁能用简单的外行术语解释一下?与@Entity中使用的数据有什么关系?

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.

虽然与 Hibernate 相关(一个 JPA 提供者),但我认为这些链接很有用:

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

在 Java EE 中,持久化上下文通常通过 EntityManager 访问.

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

https://vladmihalcea.com/wp-content/uploads/2014/07/jpaentitystates.png

这篇关于什么是持久化上下文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆