<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Jpa on Java &amp; Software Architecture Knowledge Hub</title><link>https://samirsahoo.github.io/design-patterns-hub/tags/jpa/</link><description>Recent content in Jpa on Java &amp; Software Architecture Knowledge Hub</description><generator>Hugo</generator><language>en-US</language><copyright>© 2026 Samir Kumar Sahoo (https://github.com/samirsahoo). All rights reserved.</copyright><atom:link href="https://samirsahoo.github.io/design-patterns-hub/tags/jpa/index.xml" rel="self" type="application/rss+xml"/><item><title>Spring Data JPA and the Hibernate ORM Lifecycle</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/data/spring-data-jpa-and-hibernate/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/data/spring-data-jpa-and-hibernate/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;JPA (Jakarta Persistence)&lt;/strong&gt; is the standard Java API for object-relational mapping: annotated &lt;strong&gt;entities&lt;/strong&gt; are mapped to tables and managed by an &lt;strong&gt;&lt;code&gt;EntityManager&lt;/code&gt;&lt;/strong&gt;.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Hibernate&lt;/strong&gt; is the most widely used JPA implementation.&lt;/li&gt;&#10;&lt;li&gt;&lt;strong&gt;Spring Data JPA&lt;/strong&gt; sits on top and generates &lt;strong&gt;repositories&lt;/strong&gt;, so you rarely write &lt;code&gt;EntityManager&lt;/code&gt; code yourself.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Hand-written JDBC means mapping rows to objects, tracking what changed and writing every INSERT and UPDATE yourself. ORMs automate that, but their &lt;strong&gt;automatic behaviours&lt;/strong&gt; (caching, dirty checking, lazy loading, flush timing) surprise teams that do not understand the &lt;strong&gt;persistence context&lt;/strong&gt;.&lt;/p&gt;</description></item><item><title>Entity Mappings and Fetch Strategies: Lazy vs Eager and the N+1 Problem</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/data/entity-mappings-and-fetch-strategies/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/data/entity-mappings-and-fetch-strategies/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;&lt;strong&gt;Entity mappings&lt;/strong&gt; tell JPA how classes and their associations map to tables and foreign keys. &lt;strong&gt;Fetch strategies&lt;/strong&gt; decide &lt;strong&gt;when&lt;/strong&gt; associated data is loaded: &lt;strong&gt;eagerly&lt;/strong&gt; (with the parent) or &lt;strong&gt;lazily&lt;/strong&gt; (on first access, through a proxy).&lt;/p&gt;</description></item><item><title>Querying with JPQL, the Criteria API and Specifications</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/data/jpql-and-criteria-api/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/data/jpql-and-criteria-api/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;ul&gt;&#10;&lt;li&gt;&lt;strong&gt;JPQL (Jakarta Persistence Query Language)&lt;/strong&gt; is SQL-like, but queries &lt;strong&gt;entities and their fields&lt;/strong&gt;, not tables and columns.&lt;/li&gt;&#10;&lt;li&gt;The &lt;strong&gt;Criteria API&lt;/strong&gt; builds the same queries &lt;strong&gt;programmatically and type-safely&lt;/strong&gt;. It is ideal when filters are dynamic.&lt;/li&gt;&#10;&lt;li&gt;Spring Data adds &lt;strong&gt;derived queries&lt;/strong&gt;, &lt;strong&gt;&lt;code&gt;@Query&lt;/code&gt;&lt;/strong&gt;, &lt;strong&gt;Specifications&lt;/strong&gt; and &lt;strong&gt;Query by Example&lt;/strong&gt; on top.&lt;/li&gt;&#10;&lt;/ul&gt;&#10;&lt;h2 id="the-problem"&gt;The problem&lt;a class="heading-anchor" href="#the-problem" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;Simple lookups fit method names. Real screens need optional filters (status, date range, customer, amount), sorting and pagination. Concatenating JPQL strings for that is ugly and &lt;strong&gt;dangerous&lt;/strong&gt; (injection). Native SQL everywhere loses portability and mapping.&lt;/p&gt;</description></item><item><title>Database Transactions in Spring: @Transactional, Propagation and Isolation</title><link>https://samirsahoo.github.io/design-patterns-hub/spring/data/transactions/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://samirsahoo.github.io/design-patterns-hub/spring/data/transactions/</guid><description>&lt;h2 id="simple-definition"&gt;Simple definition&lt;a class="heading-anchor" href="#simple-definition" aria-label="Link to this section"&gt;#&lt;/a&gt;&lt;/h2&gt;&#10;&lt;p&gt;A &lt;strong&gt;transaction&lt;/strong&gt; groups database operations so they &lt;strong&gt;all succeed or all fail&lt;/strong&gt; (ACID). In Spring you declare transaction boundaries with &lt;strong&gt;&lt;code&gt;@Transactional&lt;/code&gt;&lt;/strong&gt;. A proxy then begins, commits or rolls back through a &lt;strong&gt;&lt;code&gt;PlatformTransactionManager&lt;/code&gt;&lt;/strong&gt; (for example &lt;code&gt;JpaTransactionManager&lt;/code&gt;).&lt;/p&gt;</description></item></channel></rss>