EclipseLink Persistence Framework

repository·master·Indexed 42 days ago

https://github.com/eclipse-ee4j/eclipselink

A universal Java persistence framework supporting relational databases, XML, and JSON through standards such as Jakarta Persistence and Jakarta XML Binding. It is designed to run in any Java environment, including Java SE and server-side (EJB/EAR) deployments.

Tokens
171.5K
Snippets
408
Records
716
Agent score
52%

What's inside EclipseLink

  1. Overview of EclipseLink Persistence Framework

    master

    EclipseLink is a comprehensive and universal persistence framework designed to run in any Java environment. It facilitates reading and writing objects to various data sources, including:

    • Relational Databases: via Jakarta Persistence (JPA).
    • XML: via Jakarta XML Binding (JAXB).
    • EIS and Legacy Systems: via Jakarta Connectors.
    • Other formats: including JSON and Service Data Objects (SDO).
  2. What is EclipseLink?

    master

    EclipseLink is an advanced object-persistence and object-transformation framework. It is designed to bridge the gap between object-oriented Java applications and various data sources, allowing developers to focus on domain logic rather than data mapping.

    EclipseLink supports the following data types and formats:

    • Relational Data: Transactional persistence of Java objects to relational databases via JDBC drivers.
    • Object-Relational Data Types: Persistence to structured data source representations optimized for object-relational databases (e.g., Oracle Database).
    • Enterprise Information Systems (EIS): Persistence to nonrelational data sources using Java EE Connector architecture (JCA) adapters (including indexed, mapped, or XML records).
    • XML: Nontransactional, in-memory conversion between Java objects and XSD-based XML documents using JAXB.
  3. EclipseLink supported environments and servers

    master

    EclipseLink supports EJB 3.0 and the Jakarta Persistence API (JPA) in both Jakarta EE and Java SE environments. It integrates with various application servers, including:

    • Oracle WebLogic Server
    • Oracle Glassfish Server
    • JBoss Web Server
    • IBM WebSphere application server
    • SAP NetWeaver
    • Oracle Containers for Jakarta EE (OC4J)
    • Web containers such as Apache Tomcat, Eclipse Gemini, IBM WebSphere CE, and SpringSource tcServer.
  4. Implementation options for the EclipseLink persistence layer

    master

    When building a persistence layer with EclipseLink, you can choose from several implementation strategies depending on your architectural needs:

    • JPA Metadata, Annotations, and XML: Use standard JPA annotations, persistence.xml, and EclipseLink-specific JPA extensions for configuration.
    • Metadata Java API: Manually code the project, login, platform, descriptors, and mappings in Java. This is ideal for model-based applications that rely on code generation.
    • Method and Direct Field Access: Choose between using getter/setter methods (property access) or accessing fields directly.
    • Java Byte-code Weaving: Use weaving to enhance JPA entities or POJOs with features like lazy loading, change tracking, fetch groups, and internal optimizations.
  5. Use Oracle Platform-Specific APIs in EclipseLink

    master

    EclipseLink provides specialized support for Oracle Database through the org.eclipse.persistence.platform.database.OraclePlatform class and related packages. This enables advanced features such as:

    • LOB Handling: Support for BLOB and CLOB using Oracle JDBC LOBLocator.
    • Native SQL: Support for outer join syntax (+) =, hierarchical selects (connect by prior), and the RETURNING clause.
    • Sequencing: Native support for SELECT SEQ_NAME.NEXTVAL FROM DUAL.
    • Custom Functions: Support for REGEXP_LIKE, LOCATE, SYSDATE, etc.
    • XML Support: Oracle XML Database support via XMLType and XDK XML parser.
    • Advanced Features: Flashback Querying, Oracle AQ, and Oracle RAC.

    Note on LOBs: If using non-Oracle thin JDBC drivers or wrapped environments, you can disable LOBLocator usage by calling setShouldUseLocatorForLOBWrite(boolean) on the platform instance.

  6. What is Java Persistence API (JPA)?

    master
    The Java Persistence API (JPA) is a lightweight framework for Java persistence based on Plain Old Java Objects (POJOs). It provides an Object-Relational Mapping (ORM) approach, allowing you to declaratively map Java objects to relational database tables. JPA is part of the EJB 3.0 and 3.1 specifications and can be used in both EJB-compliant containers and standard Java SE environments.
  7. What is Service Data Objects (SDO)?

    master
    Service Data Objects (SDO) provide a unified view of data, similar to POJOs in Java EE, but designed for data-oriented applications. SDO allows for different modes of operation including dynamic object models, strongly typed models, XML representation, and disconnected data handling. This makes it suitable for both Java EE and Service Component Architecture (SCA) environments.
  8. What is a Descriptor in EclipseLink

    master

    A descriptor is an object that stores all the information required to represent an instance of a particular Java class in a data source (such as a database table or an XML complex type).

    Descriptors are primarily managed via the org.eclipse.persistence.descriptors package. A descriptor typically contains:

    • The persistent Java class and its corresponding data source mapping.
    • A collection of mappings for attributes and relationships.
    • Primary key information.
    • Query keys (aliases) for field names.
    • Sequence number information.
    • Optional properties for behavior tailoring (e.g., caching, identity maps, optimistic locking, event management, and query management).
  9. What is the EclipseLink Workbench?

    master

    The EclipseLink Workbench is a graphical configuration tool separate from the EclipseLink runtime. It allows developers to define EclipseLink descriptors and mappings without writing code.

    Key capabilities include:

    • Graphically configuring descriptors and mapping projects.
    • Verifying descriptor options.
    • Accessing data sources (databases or XML schemas).
    • Creating database schemas.

    Workbench is primarily intended for development when using the native EclipseLink API, MOXy, or EIS. For JPA development, tools like Eclipse Dali or Oracle JDeveloper are recommended.

    Workbench stores project information in a .mwp file, which is used only by the Workbench. To run an EclipseLink-enabled application, you must export the configuration from Workbench into a project.xml file.

  10. What is Indirection (Lazy Loading) in EclipseLink

    master

    Indirection (also known as lazy loading, lazy reading, or just-in-time reading) is a mechanism where EclipseLink uses a placeholder object for a relationship instead of immediately fetching the related data from the database. The dependent object is only read when the specific attribute is accessed.

    Benefits:

    • Significant performance improvement by avoiding unnecessary data retrieval.
    • Optimized persistence unit processing, cache access, and concurrency.
    • Essential for maintaining bidirectional relationships.

    Important Notes:

    • If you are working with collections, you must use Transparent Indirection.
    • Indirection implementation is vendor-specific; serializing entities and merging them across different vendors may not be interoperable if lazy properties are used.
  11. What is the EclipseLink Canonical Model Generator?

    master
    The Canonical Model Generator uses the Annotation Processing Tool (APT) to produce static metamodel classes for your JPA entities, mapped superclasses, and embeddable classes. These metamodel classes allow you to use the JPA 2.0 Criteria API with type-safe references to the persistent state and relationships of your managed classes.
  12. What is Dynamic JAXB/MOXy?

    master

    Dynamic JAXB/MOXy allows you to bootstrap a JAXBContext from metadata sources (like XML Schemas) without requiring pre-compiled Java domain classes. Instead of using standard POJOs, you work with DynamicEntity objects.

    Key Benefits:

    • No Recompilation: You can update metadata (XSDs) without regenerating and recompiling Java source code.
    • Dynamic Entities: Domain objects are subclasses of DynamicEntity.
    • Simple API: Use get(propertyName) and set(propertyName, propertyValue) to manipulate data.
    • In-Memory Metadata: An associated DynamicType is generated in-memory when the metadata is parsed, allowing for runtime introspection.