Apa Itu PersistenceFramework and Reference File Download Link
https://eu2.contabostorage.com/00f3241116844f24b628f46d81abb929:st1/folder10/10560/12048_session16_morego4patterns3.pptx
2026-06-01 08:19:03 - Admin
<style> body { font-family: Arial, Helvetica, sans-serif; line-height: 1.6; margin: 0; padding: 0; background-color: #f4f4f4; color: #333; } header { background-color: #0077cc; color: #fff; padding: 20px 10px; text-align: center; } nav { background-color: #e2e2e2; padding: 10px; text-align: center; } nav a { margin: 0 15px; color: #0077cc; text-decoration: none; font-weight: bold; } main { max-width: 960px; margin: 20px auto; background-color: #fff; padding: 30px; box-shadow: 0 2px 5px rgba(0,0,0,0.1); } h1, h2, h3 { color: #0077cc; } pre { background:#f0f0f0; padding:10px; overflow:auto; } code { background:#e8e8e8; padding:2px 4px; font-family: Consolas, monospace; } ul { margin-left: 20px; } </style><header> <h1>What Is a Persistence Framework?</h1></header><nav> <a href="#definition">Definition</a> <a href="#why-use">Why Use It?</a> <a href="#core-concepts">Core Concepts</a> <a href="#popular-frameworks">Popular Frameworks</a> <a href="#choose-framework">Choosing a Framework</a> <a href="#best-practices">Best Practices</a></nav><main> <section id="definition"> <h2>Definition</h2> <p>A <strong>persistence framework</strong> is a software library that abstracts the details of storing, retrieving, and managing data in a permanent storage system such as a relational database, NoSQL store, or file system. Instead of writing raw SQL or direct API calls, developers work with higherlevel objects, annotations, or configuration files, letting the framework translate those instructions into the appropriate storage commands.</p> <p>In simple terms, a persistence framework bridges the gap between inmemory objects used by an application and the data that must survive after the program stops. It handles the mapping, transaction management, caching, and often provides additional utilities such as query builders and schema migrations.</p> </section> <section id="why-use"> <h2>Why Use a Persistence Framework?</h2> <ul> <li><strong>Productivity</strong> Reduce boilerplate code for CRUD (Create, Read, Update, Delete) operations.</li> <li><strong>Maintainability</strong> Centralise dataaccess logic, making changes easier.</li> <li><strong>Portability</strong> Switch databases with minimal code changes.</li> <li><strong>Safety</strong> Builtin protection against SQL injection and other common bugs.</li> <li><strong>Performance</strong> Automatic caching, batch updates and lazy loading can improve speed.</li> </ul> </section> <section id="core-concepts"> <h2>Core Concepts</h2> <h3>ObjectRelational Mapping (ORM)</h3> <p>Most frameworks provide ORM, which maps class definitions to database tables. For example, a <code>User</code> class may correspond to a <code>users</code> table, and each field to a column.</p> <h3>Entity Lifecycle</h3> <p>Objects pass through states such as <em>transient</em>, <em>persistent</em>, and <em>detached</em>. The framework tracks changes and decides when to issue INSERT, UPDATE, or DELETE statements.</p> <h3>Session / EntityManager</h3> <p>A <code>Session</code> (or <code>EntityManager</code>) is a context that holds a collection of persistent objects and coordinates operations with the database. Transactions are normally started through this object.</p> <h3>Query Language</h3> <p>Instead of native SQL, many frameworks expose a domainspecific language (e.g., JPQL, HQL, or a fluent API) that works with objects and is databaseagnostic.</p> <h3>Caching</h3> <p>Firstlevel (sessionscoped) and secondlevel (processscoped) caches minimise roundtrips to the database.</p> </section> <section id="popular-frameworks"> <h2>Popular Persistence Frameworks</h2> <h3>Java</h3> <ul> <li><strong>Hibernate</strong> The most widely used ORM for Java; implements the JPA specification.</li> <li><strong>EclipseLink</strong> Reference implementation of JPA; supports advanced features like NoSQL extensions.</li> <li><strong>MyBatis</strong> Focuses on SQL mapping rather than full ORM; gives developers more control over queries.</li> </ul> <h3>.NET</h3> <ul> <li><strong>Entity Framework Core</strong> Microsoft's modern ORM with LINQ support.</li> <li><strong>Dapper</strong> A microORM that maps query results to objects with minimal overhead.</li> </ul> <h3>Python</h3> <ul> <li><strong>SQLAlchemy</strong> Offers both an ORM layer and a powerful SQL expression language.</li> <li><strong>Peewee</strong> Lightweight ORM for small to mediumsized projects.</li> </ul> <h3>JavaScript/Node.js</h3> <ul> <li><strong>Sequelize</strong> Promisebased ORM for PostgreSQL, MySQL, SQLite, and MSSQL.</li> <li><strong>TypeORM</strong> Works with TypeScript and supports Active Record & Data Mapper patterns.</li> </ul> </section> <section id="choose-framework"> <h2>Choosing the Right Framework</h2> <p>When evaluating a persistence framework, consider the following factors:</p> <ul> <li><strong>Project size and complexity</strong> Large enterprise systems often benefit from a fullfeatured ORM like Hibernate, while microservices may prefer a lightweight solution like Dapper.</li> <li><strong>Team expertise</strong> Choose a tool that aligns with the language and patterns your team already knows.</li> <li><strong>Database support</strong> Ensure the framework works well with your chosen DBMS(s) and any required NoSQL variants.</li> <li><strong>Performance requirements</strong> Some frameworks add abstraction overhead; benchmarking is advisable for critical paths.</li> <li><strong>Community and documentation</strong> Active communities provide faster bug fixes and more learning resources.</li> </ul> </section> <section id="best-practices"> <h2>Best Practices for Using Persistence Frameworks</h2> <ol> <li><strong>Keep entities simple</strong> Avoid business logic in entity classes; use service layers for complex operations.</li> <li><strong>Use lazy loading wisely</strong> Prevent the N+1 query problem by explicitly fetching related data when needed.</li> <li><strong>Batch writes</strong> Group INSERT/UPDATE statements to reduce network roundtrips.</li> <li><strong>Leverage transactions</strong> Wrap related operations in a single transaction to maintain data integrity.</li> <li><strong>Version entities</strong> Optimistic locking (using a version column) helps avoid lost updates in concurrent environments.</li> <li><strong>Monitor generated SQL</strong> Enable logging during development to understand what the framework sends to the database.</li> <li><strong>Separate readonly and writeheavy models</strong> Consider using CQRS (Command Query Responsibility Segregation) if the application has distinct read/write workloads.</li> </ol> </section></main>