Entity Manager
每个Entity Manager都有一个对应的Persistent Context相关,Persistent Context定义了一个scope,所有关于Entity的更新、删除等操作都是在这个scope中进行的额。而我们又是通过Entity Manager和Persistent Context进行交互的。
1. Entity Manager Interface
1)Container-Managed Entity Managers
当Application的Container(如JEE Container或如Spring这样custom container)管理了Entity Manager的lifecycle,则称这个Entity Manager是Container-Managed
在这种情况下,EntityManager实例是通过@PersistentContext注入的。

本文介绍了Java Persistence API(JPA)中的核心组件Entity Manager及其对应的Persistent Context。Entity Manager负责管理实体的生命周期,包括查找、持久化、删除和同步数据到数据库。根据管理方式,分为Container-Managed(如Transaction Scoped和Extended Scope)和Application-Managed。当事务提交时,Entity数据会更新到数据库,可通过flush方法强制同步。Persistent Units定义了由Entity Manager管理的实体类集合。
最低0.47元/天 解锁文章
1068

被折叠的 条评论
为什么被折叠?



