Prev Next

Hibernate / EclipseLink Interview questions

1. What is EclipseLink? 2. What is JPA (Jakarta Persistence API)? 3. What is the relationship between EclipseLink and Jakarta Persistence? 4. What is a Persistence Unit in EclipseLink? 5. What is persistence.xml used for? 6. What is an EntityManager in EclipseLink? 7. What is an EntityManagerFactory? 8. What is a JPA entity? 9. What are EclipseLink's core components? 10. What is EclipseLink MOXy? 11. What is class weaving in EclipseLink? 12. What is the EclipseLink shared cache (L2 cache)? 13. What is a fetch group in EclipseLink? 14. What is optimistic locking in EclipseLink and JPA? 15. What is the @Convert annotation used for? 16. What is a Customizer in EclipseLink? 17. What is JPQL? 18. What are EclipseLink query hints? 19. What is DDL generation in EclipseLink? 20. What is a UnitOfWork in EclipseLink's native API? 21. What is EclipseLink's native Session API? 22. What is static weaving in EclipseLink? 23. What are EclipseLink descriptors? 24. What is EclipseLink DBWS? 25. What is EclipseLink SDO? 26. Explain the lifecycle of a JPA entity managed by EclipseLink? 27. Why is class weaving important for lazy loading in EclipseLink? 28. How does EclipseLink's shared cache differ from Hibernate's second-level cache? 29. What is the difference between static weaving and dynamic weaving? 30. How do you configure batch fetching using EclipseLink query hints? 31. When should you use pessimistic locking instead of optimistic locking? 32. How do you troubleshoot lazy loading failures caused by missing weaving in EclipseLink? 33. What is the difference between EAGER and LAZY fetch strategies, and how does EclipseLink implement lazy loading without a live session? 34. How does EclipseLink implement change tracking for detecting entity modifications? 35. Explain the internal working of EclipseLink's cache coordination? 36. What is the difference between EclipseLink and Hibernate? 37. How do you implement multitenancy in EclipseLink? 38. Why use fetch groups instead of always fetching the full entity? 39. What is the difference between attribute change tracking and deferred change detection? 40. How does EclipseLink cache query results, and what invalidation strategies are available? 41. When would you choose isolated cache over shared cache for a multitenant entity? 42. How do you configure a Customizer to add native EclipseLink mappings not expressible via annotations? 43. What is the difference between JPQL and the EclipseLink native Expression/Criteria API? 44. Explain the internal working of EclipseLink's Unit of Work commit process? 45. How do you optimize EclipseLink performance for a high-throughput application? 46. What is the difference between EclipseLink's @Convert and JPA's standard AttributeConverter? 47. How does EclipseLink decide when to use join fetch versus batch fetch? 48. Why should you use @Version for optimistic locking instead of manual version checks? 49. What is the difference between EntityManager persistence context types: transaction-scoped vs extended? 50. How do you troubleshoot stale data issues caused by EclipseLink's shared cache?

1. What is EclipseLink?

EclipseLink is an open-source persistence framework hosted by the Eclipse Foundation, best known as the reference implementation of Jakarta Persistence (formerly the Java Persistence API, JPA). It maps Java objects to relational databases, and beyond plain ORM it also handles object-XML mapping, ...

Read full answer

2. What is JPA (Jakarta Persistence API)?

Jakarta Persistence, formerly the Java Persistence API (JPA), is a Java specification that defines how Java objects are mapped to and persisted in a relational database. It standardizes annotations like @Entity and @Id , the query language JPQL, and core runtime interfaces like EntityManager , so...

Read full answer

3. What is the relationship between EclipseLink and Jakarta Persistence?

Jakarta Persistence is the specification: a set of interfaces, annotations, and behavioral rules that any compliant provider must implement. EclipseLink is one such provider, and specifically the reference implementation , meaning it's built alongside the specification itself and used to validate...

Read full answer

4. What is a Persistence Unit in EclipseLink?

A persistence unit is a named configuration grouping a set of entity classes together with the database connection and provider settings needed to manage them. It's declared inside persistence.xml and is the boundary an EntityManagerFactory is built from. A single application can define multiple ...

Read full answer

5. What is persistence.xml used for?

persistence.xml is the standard JPA configuration file, located under META-INF/ , that defines one or more persistence units. It tells the JPA runtime which provider to use, how to connect to the database, which entity classes belong to the unit, and any additional provider-specific properties. <...

Read full answer

6. What is an EntityManager in EclipseLink?

The EntityManager is the primary JPA interface for interacting with the persistence context: it's used to persist new entities, find existing ones by primary key, execute JPQL or native queries, and manage transaction boundaries in a resource-local setup. Under the hood, EclipseLink's EntityManag...

Read full answer

7. 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...

Read full answer

8. What is a JPA entity?

An entity is a plain Java class annotated with @Entity that represents a row (or set of rows, for inheritance hierarchies) in a database table. Every entity needs an identifier field marked with @Id , corresponding to the table's primary key. @Entity @Table (name = "EMPLOYEE" ) public class Emplo...

Read full answer

9. What are EclipseLink's core components?

EclipseLink is organized into several components that each target a different persistence standard, all sharing a common underlying mapping and metadata engine. JPA/ORM - relational object-relational mapping implementing Jakarta Persistence. MOXy - object-XML and object-JSON binding implementing ...

Read full answer

10. What is EclipseLink MOXy?

MOXy is EclipseLink's implementation of Jakarta XML Binding (JAXB), used to convert Java objects to and from XML, and, as an extension beyond standard JAXB, to and from JSON as well. It uses the same @XmlRootElement , @XmlElement , and related annotations that any JAXB implementation recognizes. ...

Read full answer

11. What is class weaving in EclipseLink?

Weaving is a bytecode-enhancement step EclipseLink applies to entity classes, injecting extra fields and methods that support features standard plain Java classes can't provide on their own: transparent lazy loading of relationships, efficient attribute-level change tracking, and fetch-group-awar...

Read full answer

12. What is the EclipseLink shared cache (L2 cache)?

The shared cache, often called the second-level (L2) cache, stores entity instances at the EntityManagerFactory level, shared across every EntityManager created from that factory. This is distinct from the first-level cache (the persistence context inside a single EntityManager ), which only live...

Read full answer

13. What is a fetch group in EclipseLink?

A fetch group defines a specific subset of an entity's attributes to load in a given query, instead of always fetching every mapped field. This lets an application load only the columns it actually needs for a given use case, deferring the rest until (and unless) they're accessed later. EntityMan...

Read full answer

14. What is optimistic locking in EclipseLink and JPA?

Optimistic locking detects conflicting concurrent updates to the same row without holding a database lock for the duration of a transaction. A version column, mapped with @Version , is incremented on every update; when EclipseLink issues an update, it includes the version value read at load time ...

Read full answer

15. What is the @Convert annotation used for?

@Convert , paired with a class implementing AttributeConverter , lets an entity attribute be stored in the database as a different type than its Java representation, converting between them automatically on read and write. A common example is storing a Java enum or a custom value object as a plai...

Read full answer

16. What is a Customizer in EclipseLink?

A Customizer is a class implementing EclipseLink's DescriptorCustomizer interface, giving programmatic access to an entity's internal ClassDescriptor at startup, after annotations and XML mappings have already been processed. It's the escape hatch for configuring things that don't have a correspo...

Read full answer

17. What is JPQL?

JPQL (Jakarta Persistence Query Language) is the standard, database-agnostic query language defined by the JPA specification. It looks similar to SQL but operates on entity objects and their mapped attributes rather than directly on database tables and columns. SELECT e FROM Employee e WHERE e.de...

Read full answer

18. What are EclipseLink query hints?

Query hints are provider-specific settings passed to a JPA query via setHint() , letting an application tune how EclipseLink executes that particular query without changing standard JPQL. Because hints are outside the JPA specification, unrecognized hints are simply ignored by other providers rat...

Read full answer

19. What is DDL generation in EclipseLink?

DDL generation is EclipseLink's ability to automatically create (or drop and recreate) database tables based on an application's entity mappings, controlled through the eclipselink.ddl-generation persistence unit property.

Read full answer

20. 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-progre...

Read full answer

21. What is EclipseLink's native Session API?

Session is EclipseLink's foundational, non-JPA API for interacting with a data source, predating its JPA support and still available as a lower-level alternative or complement to it. Different session types serve different roles: a DatabaseSession manages a direct connection for a single-user app...

Read full answer

22. What is static weaving in EclipseLink?

Static weaving performs the same bytecode enhancement as dynamic (load-time) weaving, but ahead of time, as a build step, rather than when classes are loaded by the JVM at runtime. EclipseLink provides an Ant task and a Maven plugin that run against already-compiled entity classes and rewrite the...

Read full answer

23. What are EclipseLink descriptors?

A ClassDescriptor is EclipseLink's internal, runtime representation of everything it knows about how a given entity class maps to the database: its table, its fields and their column mappings, its relationships, caching policy, and query manager. Every entity has exactly one descriptor, built up ...

Read full answer

24. What is EclipseLink DBWS?

DBWS (Database Web Services) generates web service interfaces, complete with WSDL, directly from database artifacts like tables, views, and stored procedures, without requiring an application to define Java entity classes or hand-write service code first. It's aimed at scenarios where the fastest...

Read full answer

25. What is EclipseLink SDO?

SDO (Service Data Objects) is a data programming model, implemented by EclipseLink, for working with loosely-typed, dynamic data structures rather than statically-typed Java entity classes. It's designed for service-oriented architectures where data shapes can change or aren't known precisely at ...

Read full answer

26. Explain the lifecycle of a JPA entity managed by EclipseLink?

Every entity instance passes through one of four states relative to a given persistence context, and understanding the transitions between them explains a lot of otherwise-confusing EclipseLink behavior. flowchart LR New[New / Transient] -->|em.persist| Managed[Managed] Managed -->|em.detach / EM...

Read full answer

27. Why is class weaving important for lazy loading in EclipseLink?

Standard Java has no built-in way to intercept field access on a plain object, which is exactly what transparent lazy loading needs: the ability to notice when a @OneToMany or @ManyToOne relationship is actually accessed and only then go fetch it. Weaving solves this by rewriting the entity's byt...

Read full answer

28. How does EclipseLink's shared cache differ from Hibernate's second-level cache?

Both frameworks cache entity instances beyond a single persistence context to avoid redundant database hits, but they differ in default behavior and in how much external configuration is needed to get there. EclipseLink shared cache Hibernate second-level cache Enabled by default for entities, us...

Read full answer

29. What is the difference between static weaving and dynamic weaving?

Both accomplish the same bytecode transformation; they differ in when it happens and what's required to make it work. Dynamic (load-time) weaving Static (build-time) weaving Happens when the JVM loads entity classes at runtime. Happens as a build step, before the application ever runs. Requires a...

Read full answer

30. How do you configure batch fetching using EclipseLink query hints?

Batch fetching solves the classic N+1 query problem: instead of issuing a separate SQL query for each entity's related collection or reference as it's lazily accessed, EclipseLink issues one additional query that fetches the related data for every entity in the original result set at once. TypedQ...

Read full answer

31. When should you use pessimistic locking instead of optimistic locking?

Optimistic locking assumes conflicts are rare and only detects them at commit time via a version mismatch; pessimistic locking prevents conflicts up front by acquiring an actual database row lock (typically via SELECT ... FOR UPDATE ) the moment the data is read for update. Employee emp = em.find...

Read full answer

32. How do you troubleshoot lazy loading failures caused by missing weaving in EclipseLink?

A common symptom is a lazy relationship that either loads eagerly regardless of the fetch = FetchType.LAZY annotation, or throws an error when accessed outside an active persistence context, both of which usually trace back to weaving not actually being applied to the deployed entity classes. Con...

Read full answer

33. What is the difference between EAGER and LAZY fetch strategies, and how does EclipseLink implement lazy loading without a live session?

FetchType.EAGER loads a relationship immediately, as part of the owning entity's initial query. FetchType.LAZY defers loading until the relationship is actually accessed, which is more efficient when the related data often isn't needed, but introduces the classic risk of trying to access it after...

Read full answer

34. How does EclipseLink implement change tracking for detecting entity modifications?

EclipseLink supports several change-tracking policies, chosen automatically based on whether weaving is applied, that determine how it figures out which fields of a managed entity actually changed and need to be included in the next update statement. Attribute change tracking Deferred change dete...

Read full answer

35. Explain the internal working of EclipseLink's cache coordination?

Cache coordination keeps the shared (L2) cache consistent across multiple JVMs in a clustered deployment. Without it, a change committed on one node's shared cache would leave every other node holding a now-stale cached copy of the same entity, since each JVM's shared cache is otherwise entirely ...

Read full answer

36. What is the difference between EclipseLink and Hibernate?

Both are mature, widely used JPA providers, and for standard JPA-compliant code, the two are largely interchangeable. The differences that matter show up mostly in defaults, native extensions, and heritage. EclipseLink Hibernate Reference implementation of Jakarta Persistence. The most widely ado...

Read full answer

37. How do you implement multitenancy in EclipseLink?

EclipseLink supports multitenancy natively through the @Multitenant annotation, which lets multiple tenants' data coexist while keeping each tenant's queries automatically scoped to only their own rows. @Entity @Multitenant (MultitenantType . SINGLE_TABLE) @TenantDiscriminatorColumn (name = "TENA...

Read full answer

38. Why use fetch groups instead of always fetching the full entity?

Loading every mapped attribute of an entity on every query, including large text/BLOB columns or rarely-needed relationships, wastes both database bandwidth and memory when most of that data goes unused for a given operation. Fetch groups let a query specify only what it actually needs. This matt...

Read full answer

39. What is the difference between attribute change tracking and deferred change detection?

Both policies exist to answer the same question at commit time, "what actually changed on this entity", but they get there through different mechanisms with different runtime costs. Attribute change tracking Deferred change detection Records each change the instant a woven setter is called. Detec...

Read full answer

40. How does EclipseLink cache query results, and what invalidation strategies are available?

Beyond caching individual entities by primary key, EclipseLink can also cache the results of specific named or parameterized queries, avoiding re-execution of the same query entirely when the result set is likely still valid, controlled through the eclipselink.cache-usage query hint or @QueryHint...

Read full answer

41. When would you choose isolated cache over shared cache for a multitenant entity?

EclipseLink's @Cache annotation supports an isolation setting with three levels: SHARED (the default, one cache entry visible to every EntityManager from the factory), PROTECTED (shared at the reference/relationship level but isolated per-tenant for the entity's own data), and ISOLATED (entirely ...

Read full answer

42. How do you configure a Customizer to add native EclipseLink mappings not expressible via annotations?

Some EclipseLink capabilities, particularly certain native converters, advanced query redirectors, or fine-grained cache configuration, don't have a corresponding standard annotation. A DescriptorCustomizer gives programmatic access to the entity's ClassDescriptor at startup to configure exactly ...

Read full answer

43. What is the difference between JPQL and the EclipseLink native Expression/Criteria API?

JPQL is a string-based query language, parsed at runtime (or precompiled for named queries), and works well for queries known ahead of time. The JPA Criteria API and EclipseLink's own native Expression framework instead build queries programmatically as Java objects, which suits queries whose str...

Read full answer

44. Explain the internal working of EclipseLink's Unit of Work commit process?

When a transaction backed by a UnitOfWork commits, EclipseLink doesn't simply replay every change immediately; it goes through a structured sequence designed to compute the minimal, correctly-ordered set of SQL statements needed. flowchart TD A[Transaction commit triggered] --> B[Compute change s...

Read full answer

45. How do you optimize EclipseLink performance for a high-throughput application?

Most EclipseLink performance work comes down to reducing the number and size of round-trips to the database, and making sure the framework's own caching and tracking features are working with the application rather than against it. Enable and tune the shared cache - use @Cache with appropriate si...

Read full answer

46. What is the difference between EclipseLink's @Convert and JPA's standard AttributeConverter?

Standard JPA's AttributeConverter interface, paired with @Convert , is the portable, spec-defined way to transform an attribute between its Java type and a basic database column type; any JPA provider recognizes it. EclipseLink additionally ships its own broader family of native converters, which...

Read full answer

47. How does EclipseLink decide when to use join fetch versus batch fetch?

Neither strategy is chosen automatically by EclipseLink on its own; both are opt-in through explicit query hints ( eclipselink.join-fetch or eclipselink.batch ), and the right choice depends on the shape of the data being fetched. Join fetch Batch fetch Fetches the relationship in the same SQL qu...

Read full answer

48. Why should you use @Version for optimistic locking instead of manual version checks?

It's technically possible to hand-roll optimistic locking by adding your own version or timestamp column and manually checking it before every update, but that approach has to be reimplemented correctly, and consistently, everywhere an update can happen, which is both error-prone and easy to forg...

Read full answer

49. What is the difference between EntityManager persistence context types: transaction-scoped vs extended?

A transaction-scoped persistence context, the default in container-managed environments, lives only for the duration of a single transaction; once the transaction commits or rolls back, every entity managed by that EntityManager becomes detached. An extended persistence context, declared with @Pe...

Read full answer

50. How do you troubleshoot stale data issues caused by EclipseLink's shared cache?

Stale-cache symptoms usually show up as a query returning an entity's old values even though the underlying row was clearly updated, most often traced to either a cluster where cache coordination isn't configured, or a database write that bypassed EclipseLink entirely. Check for out-of-band write...

Read full answer

«
»

Comments & Discussions