Jakarta Persistence

logo

Bootstrap EntityManager in Hibernate 7: 5 Ways With JPA 3.2

Create one EntityManagerFactory per database in Hibernate 7.4, from persistence.xml, from Java code with PersistenceConfiguration or HibernatePersistenceConfiguration, or from a PersistenceUnitInfo, then open one EntityManager per unit of work with runInTransaction() and callInTransaction().

getReference vs find: JPA EntityManager Methods Compared

EntityManager find() loads an entity with a SELECT or returns null, while getReference() returns a proxy without SQL. See when each runs SQL, when EntityNotFoundException and LazyInitializationException are thrown, and how to set a foreign key without loading the entity.

About Us

HowToDoInJava provides tutorials and how-to guides on Java and related technologies.

It also shares the best practices, algorithms & solutions and frequently asked interview questions.