Hibernate / EclipseLink Interview questions
What is a UnitOfWork in EclipseLink's native API?
UnitOfWork is EclipseLink's original, native concept (predating and underlying its JPA implementation) for tracking a set of changes as a single, isolated transaction. It works with private, isolated copies of managed objects rather than the shared objects held by the parent session, so in-progress changes are invisible outside the unit of work until explicitly committed.
JPA's EntityManager is effectively a standardized wrapper around this same mechanism: calling persist(), merge(), or modifying a managed entity's fields ultimately registers those changes with an underlying UnitOfWork, and calling flush() or committing the transaction triggers that unit of work to compute the necessary SQL and commit it to the database.
Applications using pure JPA rarely interact with UnitOfWork directly, but understanding it clarifies why EclipseLink's change tracking and commit process behave the way they do, since the JPA-facing behavior is really a thin layer over this native session model inherited from TopLink.
More Related questions...