What is Persistence Context?

前端 未结 9 1797
难免孤独
难免孤独 2020-12-07 08:19

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 fo

相关标签:
9条回答
  • 2020-12-07 08:58

    In layman terms we can say that Persistence Context is an environment where entities are managed, i.e it syncs "Entity" with the database.

    0 讨论(0)
  • 2020-12-07 09:00

    Taken from this page:

    Here's a quick cheat sheet of the JPA world:

    • A Cache is a copy of data, copy meaning pulled from but living outside the database.
    • Flushing a Cache is the act of putting modified data back into the database.
    • A PersistenceContext is essentially a Cache. It also tends to have it's own non-shared database connection.
    • An EntityManager represents a PersistenceContext (and therefore a Cache)
    • An EntityManagerFactory creates an EntityManager (and therefore a PersistenceContext/Cache)
    0 讨论(0)
  • 2020-12-07 09:01

    Both the org.hibernate.Session API and javax.persistence.EntityManager API represent a context for dealing with persistent data.

    This concept is called a persistence context. Persistent data has a state in relation to both a persistence context and the underlying database.

    0 讨论(0)
提交回复
热议问题