<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Riva Tholoor Philip on Medium]]></title>
        <description><![CDATA[Stories by Riva Tholoor Philip on Medium]]></description>
        <link>https://medium.com/@riva.philip?source=rss-465f281918b5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*YnhRj2NRBLnOSMMm</url>
            <title>Stories by Riva Tholoor Philip on Medium</title>
            <link>https://medium.com/@riva.philip?source=rss-465f281918b5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 15:40:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@riva.philip/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[JAKARTA DATA: Simplify your persistence model]]></title>
            <link>https://medium.com/@riva.philip/jakarta-data-simplify-your-persistence-model-f4ca7ee2d0a8?source=rss-465f281918b5------2</link>
            <guid isPermaLink="false">https://medium.com/p/f4ca7ee2d0a8</guid>
            <category><![CDATA[jakarta]]></category>
            <category><![CDATA[websphere]]></category>
            <category><![CDATA[liberty]]></category>
            <category><![CDATA[repository-pattern]]></category>
            <category><![CDATA[persistence]]></category>
            <dc:creator><![CDATA[Riva Tholoor Philip]]></dc:creator>
            <pubDate>Sat, 09 Mar 2024 14:07:14 GMT</pubDate>
            <atom:updated>2024-03-11T14:49:21.031Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rdZ7TwRAR3fr9AVXrzeDtQ.jpeg" /></figure><p>In this blog we will discuss in brief about the evolution of Java enterprise environment from JDBC to Persistence, to the most recent feature Jakarta Data. We will also take a look at how Jakarta Data facilitates the development of enterprise applications by providing an easy framework for representing backend data handling and its persistence. This article also provides an in-depth discussion related to Jakarta Data with a few example code snippets.</p><p><strong>Evolution of Jakarta EE</strong></p><blockquote>* Initial Versions — J2EE 1.2, J2EE 1.3 and J2EE 1.4</blockquote><blockquote>* Java EE 5 — Name changed from J2EE to Java EE</blockquote><blockquote>* Jakarta 8 — Introduction of Functional Programming</blockquote><blockquote>* Jakarta 9 — API namespace moved from javax to jakarta</blockquote><blockquote>* Jakarta 10 — Current Version</blockquote><blockquote>* Jakarta 11 — Under Development. Will introduce Jakarta Data API</blockquote><p><strong>Java Database Connectivity (JDBC)</strong></p><p>Java Database Connectivity (JDBC) is a standard Application Programming Interface (API) that allows Java programs to access different database management systems. It consists of a set of interfaces and classes. Using these standard interfaces and classes, programmers can write applications that work with variety of databases that adhere to the JDBC semantics. There are a few reference implementations based on the different styles of working with the backend. These reference implementations are called JDBC drivers.</p><p>There are four types of JDBC Drivers:</p><blockquote>* Type-1 Driver (JDBC-ODBC Driver) — It translates JDBC API calls into Microsoft ODBC calls that are then passed to the ODBC driver.</blockquote><blockquote>* Type-2 Driver (Native API, Partly Java Driver) — It converts JDBC API calls into DBMS-specific client API calls.</blockquote><blockquote>* Type-3 Driver (JDBC-Net, Pure-Java Driver) — It Sends JDBC API calls to a middle-tier server that translates the calls into the DBMS-specific network protocol.</blockquote><blockquote>* Type-4 Driver (Native-Protocol, Pure-Java Driver) — It converts JDBC API calls directly into the database-specific network protocol without a middle tier.</blockquote><p>In JDBC, DataSource object is used for obtaining a database connection. For this, we can use DataSource.getConnection() method. For performing database SQL operations, we can use interfaces such as Statement, PreparedStatement or CallableStatement.</p><p>A notable drawback with JDBC is the heavy dependence on database semantics. As a result, the developers face difficulties in modelling their Java applications using object-oriented principles and best practices.</p><p><strong>Jakarta Persistence (JPA)</strong></p><p>Jakarta Persistence (formerly known as Java Persistence API or JPA) is a specification that defines the standard for the management of persistence and object / relational mapping in an enterprise Java environment. A persistence entity is a lightweight Java class whose state typically persists in a table in a relational database. The instance of such entities corresponds to individual rows in the table. Entities typically have relationships with other entities, and these relationships are expressed through Object / Relational Mapping (ORM) metadata. This metadata may be specified directly in the entity class file by using annotations or in a separate XML descriptor file (eg:- eclipselink-orm.xml). A persistence unit is a logical grouping that includes Entities, Entity Managers, ORM Mapping and Jakarta Persistence Query Language (JPQL). It is defined by a persistence.xml file.</p><p>Some examples of the Jakarta Persistence Implementations are following:</p><blockquote>* EclipseLink (Default with Websphere Liberty). Current Version is EclipseLink 4.0 based on Jakarta Persistence 3.1</blockquote><blockquote>* Hibernate</blockquote><blockquote>* OpenJPA</blockquote><blockquote>* Data Nucleus</blockquote><blockquote>* Spring Data JPA</blockquote><p><strong>Why there is a need for Jakarta Data?</strong></p><p>One of the main challenges a developer is facing while developing an enterprise application is its increasing complexity, as this application itself comprises a lot of shared applications and services. While JDBC needs programmer to directly code for the database, JPA semantics are pretty complex for learning, adopting and maintaining. That is where Jakarta Data is performing its magic. It reduces the complexity by effectively separating the repository interfaces from the persistence. It also eliminates the overhead of configuration files. Another important concern addressed is that by using Jakarta Data, we are achieving backend portability.</p><p><strong>Introducing Jakarta Data</strong></p><p>Jakarta Data specification is introduced in Jakarta 11. It provides an API for easier data access. Jakarta Data separates persistence and the model with the repository interface, thus increasing the productivity of performing common database operations. The repositories are the classes that encapsulate the data access logic, thus decoupling the persistence mechanism from the domain model. The intention of the repository pattern is to keep the specifics regarding persistence outside the application’s domain model. By implementing the Repository Pattern, Jakarta Data simplifies data access and reduces the amount of boilerplate code needed. The repository acts as a gateway for accessing persistent data of one or more entity types.</p><p>Developers only need to define an interface representing the repository and an entity representing the database table. The implementation of Jakarta Data will supply the actual implementation of the repository.</p><p>The two main repositories provided by the Data specification are:</p><blockquote>* BasicRepository — It is used for basic operations of Save and Delete of entities and Find by unique identifier</blockquote><blockquote>* CrudRepository — It is used for lifecycle/CRUD operations (Create, Read, Update and Delete)</blockquote><p>CrudRepository inherits from BasicRepository, and both inherit from base interface, DataRepository. The built-in repository interfaces are provided for convenience and are optional. You should use CrudRepository or BasicRepository depending on whether you want the pre-defined operations (CRUD and other patterns) that they provide.</p><p><strong>Example Code</strong></p><p>The exemplary Student application comprises of 4 Java classes — <strong>StudentApplication </strong>(the embodying REST application), <strong>StudentResource </strong>(the API implementation class), <strong>Student</strong> (the entity class) and <strong>StudentRepository</strong> (the Jakarta Data component).</p><p>Student.java defines the entity that is being persisted in the database with three fields: ID, name, and message.</p><p>The entity is identified by the @Enttiy annotation.</p><p>The field id is identified by the annotations @Id and @GeneratedValue, as it is a primary key and the value of the id is autogenerated.</p><pre>package stud.data;<br><br>import jakarta.persistence.Entity;<br>import jakarta.persistence.GeneratedValue;<br>import jakarta.persistence.GenerationType;<br>import jakarta.persistence.Id;<br><br>@Entity<br>public class Student {<br><br>    @Id<br>    @GeneratedValue(strategy = GenerationType.AUTO)<br>    private Long id;<br> <br>    private String name;<br>    private String message;<br><br>    // constructor/getters/setters<br>}</pre><p>The next component is StudentRepository.java interface, which is the Jakarta Data component.</p><p>StudentRepository extends CrudRepository interface and is annotated with @Repository</p><pre>package stud.data;<br><br>import jakarta.data.repository.CrudRepository;<br>import jakarta.data.repository.Repository;<br>import java.util.Optional;<br><br>@Repository<br>public interface StudentRepository extends CrudRepository&lt;Student, Long&gt; {<br>    Optional&lt;Student&gt; findByNameIgnoreCase(String name);<br>}</pre><p>StudentResource.java exposes an API method for retrieving a student</p><pre>package stud.data;<br><br>import jakarta.inject.Inject;<br>import jakarta.ws.rs.core.MediaType;<br>import java.util.List;<br><br>    @Path(&quot;/students)<br>    public class StudentResource {<br><br>    @Inject<br>    private StudentRepository studentRepository;<br>    <br>    @GET<br>    @Path(&quot;/{name}&quot;)<br>    @Produces(MediaType.TEXT_PLAIN)<br>    public String findOne(@PathParam(&quot;name&quot;) String name) {<br>     return studentRepository.findByNameIgnoreCase(name)<br>       .map(Student::getMessage)<br>       .orElse(name + &quot; not found&quot;);<br>    }<br>}</pre><p>StudentApplication.java configures the Jakarta REST application.</p><pre>package stud.data;<br><br>import jakarta.ws.rs.ApplicationPath;<br>import jakarta.ws.rs.core.Application;<br><br>@ApplicationPath(&quot;/api&quot;)<br>public class StudentApplication extends Application {<br>}</pre><p><strong>Additional information</strong></p><p>First Version: Jakarta Data 1.0</p><p>Minimum Java SE Version: Java 17 or higher</p><p>An additional annotation @Repository is introduced for defining a repository.</p><p><strong>Summary</strong></p><p>Jakarta Data is an exciting addition to Jakarta EE. It increases developer productivity and code quality by preventing developers from composing error-prone boilerplate code. Jakarta Data will be available in all products compatible with the Jakarta EE 11 platform. Jakarta Data and Jakarta Persistence API are totally agnostic to the underlying persistence mechanism, so any relational database can be used.</p><p><strong>References</strong></p><p>1) Jakarta Data 1.0 specification documents — <a href="https://jakarta.ee/specifications/data/1.0/">https://jakarta.ee/specifications/data/1.0/</a></p><p>2) Jakarta EE 11 specification updates from Eclipse Foundation — <a href="https://newsroom.eclipse.org/eclipse-newsletter/2023/august/jakarta-ee-11-next-major-jakarta-ee-update-shaping">https://newsroom.eclipse.org/eclipse-newsletter/2023/august/jakarta-ee-11-next-major-jakarta-ee-update-shaping</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f4ca7ee2d0a8" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>