Hibernate / EclipseLink Interview questions
What is an EntityManagerFactory?
The EntityManagerFactory is the thread-safe, heavyweight object responsible for creating EntityManager instances for a given persistence unit. It's typically created once per persistence unit, at application startup, via Persistence.createEntityManagerFactory("myPU"), and reused for the lifetime of the application.
Because building it involves parsing persistence.xml, scanning entity metadata, and initializing EclipseLink's internal session and cache infrastructure, creating a new factory is expensive; the common mistake to avoid is creating a fresh EntityManagerFactory per request instead of per application, which throws away EclipseLink's shared cache and metadata setup work on every single call.
More Related questions...