PersistenceUnit
injects an EntityManagerFactory
, and PersistenceContext
injects an EntityManager
. It’s generally better to use PersistenceContext
unless you really need to manage the EntityManager
lifecycle manually.
More Related Contents:
- When to use EntityManager.find() vs EntityManager.getReference() with JPA
- No Persistence provider for EntityManager named X
- Sharing a persistence unit across components in a .ear file
- No Persistence provider for EntityManager named
- What’s the difference between JPA and Hibernate? [closed]
- Can someone explain mappedBy in JPA and Hibernate?
- Confusion: @NotNull vs. @Column(nullable = false) with JPA and Hibernate
- Why does JPA have a @Transient annotation?
- How to create and handle composite primary key in JPA
- Persistence unit as RESOURCE_LOCAL or JTA?
- Please explain about insertable=false and updatable=false in reference to the JPA @Column annotation
- @PreUpdate and @Prepersist in hibernate/JPA (using session)
- Hibernate bidirectional @ManyToOne, updating the not owning side not working
- JPA map collection of Enums
- MappedSuperclass – Change SequenceGenerator in Subclass
- persistence.xml different transaction-type attributes
- JPA Multiple Embedded fields
- Hibernate: “Field ‘id’ doesn’t have a default value”
- When should EntityManagerFactory instance be created/opened?
- How to set the timeout period on a JPA EntityManager query
- Difference between a “jta-datasource” and a ” resource-local ” datasource?
- LOAD and CACHE application-scoped data with @Singleton and @Stateless
- What is Persistence Context?
- Name attribute in @Entity and @Table
- When to use DiscriminatorValue annotation in hibernate
- What’s the difference between the IN and MEMBER OF JPQL operators?
- One-To-Many Relationship with Join Table
- How to create join table with JPA annotations?
- How to auto detect entities in JPA 2.0
- JPA: difference between @JoinColumn and @PrimaryKeyJoinColumn?