<?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 Prabin Neupane on Medium]]></title>
        <description><![CDATA[Stories by Prabin Neupane on Medium]]></description>
        <link>https://medium.com/@prabin.neupane.work?source=rss-2d8a6f406d2f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*sJO-xgP1cRRug9Dh</url>
            <title>Stories by Prabin Neupane on Medium</title>
            <link>https://medium.com/@prabin.neupane.work?source=rss-2d8a6f406d2f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 24 Nov 2026 16:01:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@prabin.neupane.work/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[Supercharge Your Spring Boot Debugging: A Deep Dive into JRebel]]></title>
            <link>https://medium.com/@prabin.neupane.work/supercharge-your-spring-boot-debugging-a-deep-dive-into-jrebel-2447e7aefd0b?source=rss-2d8a6f406d2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2447e7aefd0b</guid>
            <dc:creator><![CDATA[Prabin Neupane]]></dc:creator>
            <pubDate>Sat, 27 Jul 2024 11:23:07 GMT</pubDate>
            <atom:updated>2024-07-27T11:37:55.375Z</atom:updated>
            <content:encoded><![CDATA[<p>As Spring Boot developers, we’re constantly seeking ways to optimize our workflow. One of the most significant bottlenecks in the development process is the time spent waiting for application restarts after code changes. Enter JRebel: a powerful tool that’s changing the game for Spring Boot debugging. Let’s explore how to set it up and why it’s becoming an essential part of many developers’ toolkits.</p><h3>The Evolution of Spring Boot Debugging</h3><ol><li><strong>Traditional Debugging</strong>: Full application restart for every change.</li><li><strong>Spring Boot DevTools</strong>: Faster restarts, but still requires reloading.</li><li><strong>JRebel</strong>: Hot reloading without restarts, preserving application state.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*WRjXarb-pQdLYA9ccylm9Q.png" /><figcaption>pic: jRebel</figcaption></figure><h3>Setting Up JRebel: The JAR File Method</h3><p>While JRebel offers a plugin for IDEs like IntelliJ IDEA, many developers prefer the flexibility and control of the JAR file method. Here’s how to set it up:</p><ol><li><strong>Download JRebel</strong>: Obtain the JRebel JAR file from the official website.</li><li><strong>Activate JRebel</strong>:</li></ol><ul><li>Open a terminal and navigate to the directory containing the JRebel JAR.</li><li>Run the following command:</li></ul><pre>java -jar jrebel.jar</pre><ul><li>This will generate an activation URL. Copy this URL.</li></ul><p><strong>3. Configure Your Spring Boot Application</strong>:</p><ul><li>Install Jrebel plugin .</li></ul><p>After installation it will redirect to activation , the activation url will be provided by the running jrebel jar paste and restart IDEA )</p><p>Alternatively (Manual configuration)</p><ul><li>Create a rebel.xml file in your project&#39;s src/main/resources directory.</li><li>Add the following content:</li></ul><pre>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;<br>&lt;application xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;<br>             xmlns=&quot;http://www.zeroturnaround.com&quot;<br>             xsi:schemaLocation=&quot;http://www.zeroturnaround.com http://update.zeroturnaround.com/jrebel/rebel-2_3.xsd&quot;&gt;<br>    &lt;classpath&gt;<br>        &lt;dir name=&quot;${rebel.project.path}/target/classes&quot;&gt;&lt;/dir&gt;<br>    &lt;/classpath&gt;<br>&lt;/application&gt;</pre><ul><li>Replace ${rebel.project.path} with your actual project path.</li></ul><p><strong>4. Configure Your IDE</strong>:</p><ul><li>In IntelliJ IDEA, go to Run &gt; Edit Configurations.</li><li>Select your Spring Boot run configuration.</li><li>In the VM options field, add:</li></ul><pre>-javaagent:/path/to/jrebel.jar</pre><p>Replace /path/to/jrebel.jar with the actual path to your JRebel JAR file.</p><p><strong>5. Activate JRebel in Your Application</strong>:</p><ul><li>Add the following property to your application.properties or application.yml:</li></ul><pre>rebel.remote_plugin_name=spring</pre><p>Paste the activation URL you obtained earlier into your application’s configuration.</p><h3>Why JRebel Outperforms Traditional Debugging</h3><ol><li><strong>Instant Updates</strong>: Changes are reflected immediately without full restarts.</li><li><strong>State Preservation</strong>: Application state is maintained during updates.</li><li><strong>Framework Integration</strong>: Deep integration with Spring Boot for seamless configuration and bean updates.</li></ol><h3>The Inner Workings of JRebel</h3><p>JRebel’s efficiency stems from its sophisticated bytecode manipulation:</p><ol><li><strong>Class Redefinition</strong>: JRebel modifies bytecode to make classes updateable at runtime.</li><li><strong>Incremental Updates</strong>: Only changed portions of code are reloaded.</li><li><strong>Resource Tracking</strong>: JRebel monitors resources for changes and updates them in real-time.</li></ol><h3>Quantifying the Time Savings</h3><p>Consider a typical Spring Boot application that takes 45 seconds to restart. If a developer makes 20 changes per day:</p><ul><li>Without JRebel: 20 * 45 seconds = 900 seconds (15 minutes) lost to restarts daily.</li><li>With JRebel: Near-instant updates, saving potentially hours each week.</li></ul><h3>Best Practices for JRebel Usage</h3><ol><li><strong>Exclude unnecessary directories</strong>: Optimize rebel.xml to monitor only essential paths.</li><li><strong>Use with version control</strong>: Ensure rebel.xml is properly managed in your VCS.</li><li><strong>Combine with other tools</strong>: JRebel works well alongside tools like Lombok or MapStruct.</li></ol><h3>Conclusion</h3><p>JRebel represents a paradigm shift in Spring Boot debugging. By eliminating time-consuming restarts and preserving application state, it allows developers to maintain their focus and significantly boost productivity. While it comes with a learning curve and a cost, the time savings and improved development experience make it a worthwhile investment for many Spring Boot teams.</p><p>Have you integrated JRebel into your Spring Boot workflow? Share your experiences and tips in the comments below!</p><p>This blog post provides a comprehensive guide to setting up and using JRebel with Spring Boot, focusing on the JAR file method as requested. It covers the setup process, explains the benefits, and includes best practices for optimal usage. Is there any aspect you’d like me to expand upon or modify?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2447e7aefd0b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MyBatis in Spring Boot: A Comprehensive Guide to Efficient Database Access]]></title>
            <link>https://medium.com/@prabin.neupane.work/mybatis-in-spring-boot-a-comprehensive-guide-to-efficient-database-access-8beea1491ece?source=rss-2d8a6f406d2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8beea1491ece</guid>
            <dc:creator><![CDATA[Prabin Neupane]]></dc:creator>
            <pubDate>Tue, 16 Jul 2024 13:21:22 GMT</pubDate>
            <atom:updated>2024-07-27T11:30:14.690Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of Java enterprise development, choosing the right database access strategy can significantly impact your application’s performance and maintainability. While JPA (Java Persistence API) has been a go-to solution for many developers, MyBatis offers a compelling alternative — or complement — that can enhance your data access layer. In this comprehensive guide, we’ll explore how to integrate MyBatis with Spring Boot, compare it with JPA, JDBC, and raw MySQL queries, and demonstrate its capabilities through increasingly complex examples.</p><h3>Table of Contents</h3><ol><li><a href="#introduction-to-mybatis">Introduction to MyBatis</a></li><li><a href="#setting-up-mybatis-in-spring-boot">Setting Up MyBatis in Spring Boot</a></li><li><a href="#mybatis-vs-jpa-vs-jdbc-vs-mysql-a-detailed-comparison">MyBatis vs JPA vs JDBC vs MySQL: A Detailed Comparison</a></li><li><a href="#query-complexity-showcase">Query Complexity Showcase</a></li></ol><ul><li><a href="#basic-queries">Basic Queries</a></li><li><a href="#intermediate-queries">Intermediate Queries</a></li><li><a href="#advanced-queries">Advanced Queries</a></li><li><a href="#complex-queries">Complex Queries</a></li></ul><p><a href="#performance-considerations">5. Performance Considerations</a></p><p><a href="#when-to-use-mybatis">6.When to Use MyBatis</a></p><p><a href="#conclusion">7.Conclusion</a></p><h3>Introduction to MyBatis</h3><p>MyBatis is a persistence framework that bridges the gap between your Java code and your database. It provides a layer of abstraction over JDBC, allowing you to write SQL queries directly while handling the complexities of parameter mapping and result set handling.</p><p><strong>Key features of MyBatis include:</strong></p><ul><li>SQL mapping using XML or annotations</li><li>Dynamic SQL generation</li><li>Advanced result mapping</li><li>Stored procedure support</li><li>Integration with various data sources and cache implementations</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/135/1*ikadkI1_Ual0m9lirjlKQQ.jpeg" /><figcaption>MyBatis</figcaption></figure><h3>Setting Up MyBatis in Spring Boot</h3><p>Integrating MyBatis into your Spring Boot application is straightforward. Here’s how to get started:</p><ol><li>Add the MyBatis Spring Boot Starter to your pom.xml:</li></ol><pre>&lt;dependency&gt;<br>    &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt;<br>    &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt;<br>    &lt;version&gt;2.2.0&lt;/version&gt;<br>&lt;/dependency&gt;</pre><p>2. Configure your database connection in application.properties:</p><pre>spring.datasource.url=jdbc:mysql://localhost:3306/yourdb<br>spring.datasource.username=your_username<br>spring.datasource.password=your_password<br>spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver<br><br>mybatis.mapper-locations=classpath:mappers/*.xml<br>mybatis.type-aliases-package=com.yourpackage.model</pre><p>3. Create your entity classes and mapper interfaces, and you’re ready to go!</p><h3>MyBatis vs JPA vs MySQL: A Comparison</h3><p>Let’s compare these technologies across several dimensions:</p><ol><li><strong>Learning Curve</strong></li></ol><ul><li>MySQL: Steep, requires in-depth SQL knowledge</li><li>JPA: Gentle, high-level abstraction hides many complexities</li><li>MyBatis: Moderate, balances SQL knowledge with Java integration</li></ul><p><strong>2. Control over SQL</strong></p><ul><li>MySQL: Complete control, write raw SQL</li><li>JPA: Limited control, SQL generated by the ORM</li><li>MyBatis: High control, SQL in annotations or XML, easily customizable</li></ul><p><strong>3. Performance</strong></p><ul><li>MySQL: Highest potential performance, but requires careful optimization</li><li>JPA: Good performance for most cases, can be slower for complex queries</li><li>MyBatis: High performance, close to raw SQL with better organization</li></ul><p><strong>4. Maintainability</strong></p><ul><li>MySQL: Low maintainability, SQL scattered throughout the codebase</li><li>JPA: High maintainability, changes to entities automatically reflected in database</li><li>MyBatis: Good maintainability, SQL separated from Java code but still easily manageable</li></ul><h3>Query Complexity Showcase</h3><p>Let’s compare how MySQL, JPA, and MyBatis handle queries of increasing complexity.</p><h3>Basic Queries</h3><ol><li><strong>MySQL</strong></li></ol><pre>SELECT * FROM users WHERE id = 1;</pre><p>2. JPA</p><pre>@Repository<br>public interface UserRepository extends JpaRepository&lt;User, Long&gt; {<br>    User findById(Long id);<br>}<br><br>// Usage<br>User user = userRepository.findById(1L);</pre><p><strong>3. MyBatis</strong></p><pre>@Mapper<br>public interface UserMapper {<br>    @Select(&quot;SELECT * FROM users WHERE id = #{id}&quot;)<br>    User getUserById(Long id);<br>}<br><br>// Usage<br>User user = userMapper.getUserById(1L);</pre><h3>Intermediate Queries</h3><p>Let’s consider a more complex query: finding users by a combination of criteria.</p><ol><li><strong>MySQL</strong></li></ol><pre>SELECT * FROM users <br>WHERE username LIKE &#39;%john%&#39; <br>AND email LIKE &#39;%@example.com&#39; <br>AND created_at &gt; &#39;2023-01-01&#39;;</pre><p>2. JPA</p><pre>@Repository<br>public interface UserRepository extends JpaRepository&lt;User, Long&gt; {<br>    List&lt;User&gt; findByUsernameContainingAndEmailContainingAndCreatedAtAfter(<br>        String username, String email, LocalDate createdAt);<br>}<br><br>// Usage<br>List&lt;User&gt; users = userRepository.findByUsernameContainingAndEmailContainingAndCreatedAtAfter(<br>    &quot;john&quot;, &quot;@example.com&quot;, LocalDate.of(2023, 1, 1));@Repository<br>public interface UserRepository extends JpaRepository&lt;User, Long&gt; {<br>    User findById(Long id);<br>}</pre><p><strong>3. MyBatis</strong></p><pre>@Mapper<br>public interface UserMapper {<br>    @Select(&quot;SELECT * FROM users &quot; +<br>            &quot;WHERE username LIKE CONCAT(&#39;%&#39;, #{username}, &#39;%&#39;) &quot; +<br>            &quot;AND email LIKE CONCAT(&#39;%&#39;, #{email}, &#39;%&#39;) &quot; +<br>            &quot;AND created_at &gt; #{createdAt}&quot;)<br>    List&lt;User&gt; findUsers(@Param(&quot;username&quot;) String username, <br>                         @Param(&quot;email&quot;) String email, <br>                         @Param(&quot;createdAt&quot;) LocalDate createdAt);<br>}<br><br>// Usage<br>List&lt;User&gt; users = userMapper.findUsers(&quot;john&quot;, &quot;@example.com&quot;, LocalDate.of(2023, 1, 1));</pre><h3>Advanced Queries</h3><p>Now, let’s look at a more advanced scenario: a paginated search with sorting and multiple join conditions.</p><ol><li><strong>MySQL</strong></li></ol><pre>SELECT u.*, d.name as department_name, r.name as role_name<br>FROM users u<br>JOIN departments d ON u.department_id = d.id<br>JOIN roles r ON u.role_id = r.id<br>WHERE u.username LIKE &#39;%john%&#39;<br>AND d.name = &#39;Engineering&#39;<br>ORDER BY u.created_at DESC<br>LIMIT 10 OFFSET 20;</pre><p>2. JPA</p><pre>@Repository<br>public interface UserRepository extends JpaRepository&lt;User, Long&gt; {<br>    @Query(&quot;SELECT new com.example.UserDTO(u.id, u.username, d.name, r.name) &quot; +<br>           &quot;FROM User u &quot; +<br>           &quot;JOIN u.department d &quot; +<br>           &quot;JOIN u.role r &quot; +<br>           &quot;WHERE u.username LIKE CONCAT(&#39;%&#39;, :username, &#39;%&#39;) &quot; +<br>           &quot;AND d.name = :departmentName&quot;)<br>    Page&lt;UserDTO&gt; findUsersWithDepartmentAndRole(<br>        @Param(&quot;username&quot;) String username,<br>        @Param(&quot;departmentName&quot;) String departmentName,<br>        Pageable pageable);<br>}<br><br>// Usage<br>PageRequest pageRequest = PageRequest.of(2, 10, Sort.by(&quot;createdAt&quot;).descending());<br>Page&lt;UserDTO&gt; userPage = userRepository.findUsersWithDepartmentAndRole(&quot;john&quot;, &quot;Engineering&quot;, pageRequest);</pre><p><strong>3. MyBatis</strong></p><pre>@Mapper<br>public interface UserMapper {<br>    @Select(&quot;SELECT u.*, d.name as department_name, r.name as role_name &quot; +<br>            &quot;FROM users u &quot; +<br>            &quot;JOIN departments d ON u.department_id = d.id &quot; +<br>            &quot;JOIN roles r ON u.role_id = r.id &quot; +<br>            &quot;WHERE u.username LIKE CONCAT(&#39;%&#39;, #{username}, &#39;%&#39;) &quot; +<br>            &quot;AND d.name = #{departmentName} &quot; +<br>            &quot;ORDER BY u.created_at DESC &quot; +<br>            &quot;LIMIT #{pageSize} OFFSET #{offset}&quot;)<br>    @Results({<br>        @Result(property = &quot;id&quot;, column = &quot;id&quot;),<br>        @Result(property = &quot;username&quot;, column = &quot;username&quot;),<br>        @Result(property = &quot;departmentName&quot;, column = &quot;department_name&quot;),<br>        @Result(property = &quot;roleName&quot;, column = &quot;role_name&quot;)<br>    })<br>    List&lt;UserDTO&gt; findUsersWithDepartmentAndRole(<br>        @Param(&quot;username&quot;) String username,<br>        @Param(&quot;departmentName&quot;) String departmentName,<br>        @Param(&quot;pageSize&quot;) int pageSize,<br>        @Param(&quot;offset&quot;) int offset);<br>}<br><br>// Usage<br>List&lt;UserDTO&gt; users = userMapper.findUsersWithDepartmentAndRole(&quot;john&quot;, &quot;Engineering&quot;, 10, 20);</pre><h3>Complex Queries</h3><p>For our complex query example, let’s consider a scenario where we need to perform a hierarchical query with recursive CTEs (Common Table Expressions), which is challenging for ORMs like JPA.</p><p>Scenario: Fetch all subordinates of a given employee, up to 3 levels deep, along with their department and total subordinates count.</p><ol><li><strong>MySQL</strong></li></ol><pre>WITH RECURSIVE emp_hierarchy AS (<br>    SELECT id, name, manager_id, department_id, 1 as level<br>    FROM employees<br>    WHERE id = 1  -- Starting employee ID<br><br>    UNION ALL<br><br>    SELECT e.id, e.name, e.manager_id, e.department_id, eh.level + 1<br>    FROM employees e<br>    JOIN emp_hierarchy eh ON e.manager_id = eh.id<br>    WHERE eh.level &lt; 3<br>)<br>SELECT eh.id, eh.name, eh.level, d.name as department_name, <br>       COUNT(sub.id) as subordinates_count<br>FROM emp_hierarchy eh<br>LEFT JOIN employees sub ON sub.manager_id = eh.id<br>JOIN departments d ON eh.department_id = d.id<br>GROUP BY eh.id, eh.name, eh.level, d.name<br>ORDER BY eh.level, eh.name;</pre><p>2. <strong>JPA</strong> : JPA doesn’t natively support recursive queries. You’d typically need to use a native query:</p><pre>@Repository<br>public interface EmployeeRepository extends JpaRepository&lt;Employee, Long&gt; {<br>    @Query(nativeQuery = true, value = <br>        &quot;WITH RECURSIVE emp_hierarchy AS ( ... )  -- Full SQL as above<br>         SELECT eh.id, eh.name, eh.level, d.name as department_name, <br>                COUNT(sub.id) as subordinates_count<br>         FROM emp_hierarchy eh<br>         LEFT JOIN employees sub ON sub.manager_id = eh.id<br>         JOIN departments d ON eh.department_id = d.id<br>         GROUP BY eh.id, eh.name, eh.level, d.name<br>         ORDER BY eh.level, eh.name&quot;)<br>    List&lt;Object[]&gt; getEmployeeHierarchy(@Param(&quot;startEmployeeId&quot;) Long startEmployeeId);<br>}<br><br>// Usage<br>List&lt;Object[]&gt; hierarchyData = employeeRepository.getEmployeeHierarchy(1L);<br>List&lt;EmployeeHierarchyDTO&gt; result = hierarchyData.stream()<br>    .map(row -&gt; new EmployeeHierarchyDTO(<br>        ((Number) row[0]).longValue(),<br>        (String) row[1],<br>        ((Number) row[2]).intValue(),<br>        (String) row[3],<br>        ((Number) row[4]).intValue()<br>    ))<br>    .collect(Collectors.toList());</pre><p><strong>3. MyBatis : </strong>MyBatis shines in scenarios like this, where you need fine-grained control over complex SQL while still maintaining a clean Java interface.</p><pre>@Mapper<br>public interface EmployeeMapper {<br>    @Select(&quot;WITH RECURSIVE emp_hierarchy AS ( &quot; +<br>            &quot;    SELECT id, name, manager_id, department_id, 1 as level &quot; +<br>            &quot;    FROM employees &quot; +<br>            &quot;    WHERE id = #{startEmployeeId} &quot; +<br>            &quot;    UNION ALL &quot; +<br>            &quot;    SELECT e.id, e.name, e.manager_id, e.department_id, eh.level + 1 &quot; +<br>            &quot;    FROM employees e &quot; +<br>            &quot;    JOIN emp_hierarchy eh ON e.manager_id = eh.id &quot; +<br>            &quot;    WHERE eh.level &lt; 3 &quot; +<br>            &quot;) &quot; +<br>            &quot;SELECT eh.id, eh.name, eh.level, d.name as department_name, &quot; +<br>            &quot;       COUNT(sub.id) as subordinates_count &quot; +<br>            &quot;FROM emp_hierarchy eh &quot; +<br>            &quot;LEFT JOIN employees sub ON sub.manager_id = eh.id &quot; +<br>            &quot;JOIN departments d ON eh.department_id = d.id &quot; +<br>            &quot;GROUP BY eh.id, eh.name, eh.level, d.name &quot; +<br>            &quot;ORDER BY eh.level, eh.name&quot;)<br>    @Results({<br>        @Result(property = &quot;id&quot;, column = &quot;id&quot;),<br>        @Result(property = &quot;name&quot;, column = &quot;name&quot;),<br>        @Result(property = &quot;level&quot;, column = &quot;level&quot;),<br>        @Result(property = &quot;departmentName&quot;, column = &quot;department_name&quot;),<br>        @Result(property = &quot;subordinatesCount&quot;, column = &quot;subordinates_count&quot;)<br>    })<br>    List&lt;EmployeeHierarchyDTO&gt; getEmployeeHierarchy(@Param(&quot;startEmployeeId&quot;) Long startEmployeeId);<br>}<br><br>// Usage<br>List&lt;EmployeeHierarchyDTO&gt; hierarchy = employeeMapper.getEmployeeHierarchy(1L);</pre><h3>Performance Considerations</h3><p>When it comes to performance:</p><ol><li><strong>Raw MySQL</strong>: Offers the highest potential performance, but requires careful query optimization.</li><li><strong>JPA</strong>: Generally provides good performance for most use cases, with built-in caching and lazy loading. However, it can be slower for very complex queries or when fetching large amounts of data.</li><li><strong>MyBatis</strong>: Offers performance close to raw SQL, as it provides a thin layer over JDBC. It allows for fine-grained control over SQL while handling resource management and providing a clean Java interface.</li></ol><p>In practice, MyBatis often outperforms JPA for complex queries and large datasets, while maintaining better code organization than raw SQL. However, for simple CRUD operations on single entities, JPA can be more convenient and perform adequately.</p><h3>When to Use MyBatis</h3><p>MyBatis is particularly well-suited for:</p><ol><li><strong>Complex Queries</strong>: When your application requires complex SQL queries, especially those involving multiple joins, subqueries, or advanced database features.</li><li><strong>Performance-Critical Applications</strong>: In situations where you need to squeeze out every bit of database performance.</li><li><strong>Legacy Database Integration</strong>: When working with an existing database schema that doesn’t map well to JPA entities.</li><li><strong>Mixed Read/Write Workloads</strong>: MyBatis excels in applications that have a mix of complex read queries and simple write operations.</li><li><strong>Gradual Migration</strong>: When gradually migrating a large application from raw SQL to a more structured approach.</li><li><strong>Complementing JPA</strong>: MyBatis can be used alongside JPA in the same application, handling the complex queries while leaving simple CRUD operations to JPA.</li></ol><h3>Conclusion</h3><p>While JPA remains popular for its ease of use and automatic ORM capabilities, MyBatis offers a compelling alternative that bridges the gap between raw SQL and high-level ORM abstractions. By providing fine-grained control over SQL queries while maintaining a clean and type-safe Java interface, MyBatis enables developers to build high-performance, maintainable database access layers.</p><p>The examples we’ve explored demonstrate how MyBatis shines in handling queries of varying complexity, from simple CRUD operations to complex hierarchical data retrieval. Its ability to cleanly separate SQL from Java code, combined with its powerful dynamic SQL capabilities, makes it an excellent choice for applications that require precise control over database interactions.</p><p>In many real-world scenarios, the best approach might be to use MyBatis in conjunction with JPA, leveraging the strengths of each framework where they are most applicable. This hybrid approach allows you to use JPA for simple entity management and basic queries, while turning to MyBatis for complex, performance-critical database operations.</p><p>By understanding the strengths and use cases of MyBatis, you can make informed decisions about your data access strategy, ultimately leading to more efficient, maintainable, and performant Spring Boot applications</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8beea1491ece" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elevating Validation: The Combinator Pattern in Functional Programming]]></title>
            <link>https://medium.com/@prabin.neupane.work/elevating-validation-the-combinator-pattern-in-functional-programming-bc01eb16705a?source=rss-2d8a6f406d2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/bc01eb16705a</guid>
            <dc:creator><![CDATA[Prabin Neupane]]></dc:creator>
            <pubDate>Sun, 14 Jul 2024 15:48:51 GMT</pubDate>
            <atom:updated>2024-07-14T15:48:51.997Z</atom:updated>
            <content:encoded><![CDATA[<p>In the world of software development, data validation is a critical aspect that ensures the integrity and reliability of our applications. Traditional approaches to validation often lead to complex, hard-to-maintain code. However, functional programming offers an elegant solution: the Combinator Pattern. In this post, we’ll explore how this pattern can transform our validation logic, making it more modular, reusable, and easier to reason about.</p><h3>The Problem with Traditional Validation</h3><p>Let’s start by looking at a typical validation service:</p><pre>public class CustomerValidatorService {<br>    private boolean isEmailValid(String email) {<br>        return email.contains(&quot;@&quot;);<br>    }<br>    private boolean isNameValid(String name) {<br>        return name.contains(&quot;+0&quot;);<br>    }<br>    private boolean isAddressValid(String address) {<br>        return address.contains(&quot;//s+$&quot;);<br>    }<br>    private boolean isAdult(LocalDate dob) {<br>        return Period.between(dob, LocalDate.now()).getYears() &gt; 10;<br>    }<br>    public boolean isValid(Customer customer) {<br>        return isEmailValid(customer.getEmail()) &amp;&amp;<br>                isNameValid(customer.getName()) &amp;&amp;<br>                isAddressValid(customer.getAddress()) &amp;&amp;<br>                isAdult(customer.getDob());<br>    }<br>}</pre><p>This approach has several drawbacks:</p><ol><li>It’s not flexible — adding new validation rules requires modifying the existing class.</li><li>It’s hard to compose — you can’t easily combine validation rules in different ways.</li><li>It doesn’t provide detailed error information — you only get a boolean result.</li></ol><h3>Enter the Combinator Pattern:</h3><p>The Combinator Pattern allows us to build complex behaviors by composing smaller, simpler pieces. Here’s how we can apply it to our validation problem:</p><pre>public interface CustomerRegistrationValidator <br>        extends Function&lt;Customer, CustomerRegistrationValidator.ValidationResult&gt; {<br><br>    static CustomerRegistrationValidator isEmailValid() {<br>        return customer -&gt; {<br>            Pattern emailPattern = Pattern.compile(&quot;^[A-Za-z0-9+_.-]+@(.+)$&quot;);<br>            return emailPattern.matcher(customer.getEmail()).matches() ?<br>                    ValidationResult.SUCCESS : ValidationResult.EMAIL_NOT_VALID;<br>        };<br>    }<br><br>    // ... other validation methods ...<br><br>    default CustomerRegistrationValidator and(CustomerRegistrationValidator other) {<br>        return customer -&gt; {<br>            ValidationResult result = this.apply(customer);<br>            return result.equals(ValidationResult.SUCCESS) ? other.apply(customer) : result;<br>        };<br>    }<br><br>    enum ValidationResult {<br>        SUCCESS,<br>        PHONE_NUMBER_NOT_VALID,<br>        EMAIL_NOT_VALID,<br>        IS_NOT_AN_ADULT,<br>        ADDRESS_NOT_VALID,<br>        NAME_NOT_VALID<br>    }<br>}</pre><h3>Benefits of the Combinator Pattern</h3><ol><li><strong>Modularity</strong>: Each validation rule is a separate function, making it easy to add, remove, or modify rules.</li><li><strong>Composability</strong>: The and method allows us to combine validators in any way we need.</li><li><strong>Detailed Feedback</strong>: Instead of just true/false, we get specific validation results.</li><li><strong>Reusability</strong>: Validation rules can be easily shared and reused across different parts of the application.</li></ol><h3>Using the Combinator Pattern</h3><p>Here’s how we can use our new validator:</p><pre>CustomerRegistrationValidator validator = CustomerRegistrationValidator<br>    .isEmailValid()<br>    .and(CustomerRegistrationValidator.isPhoneNumberValid())<br>    .and(CustomerRegistrationValidator.isAddressValid())<br>    .and(CustomerRegistrationValidator.isNameValid())<br>    .and(CustomerRegistrationValidator.isAdult());<br><br>CustomerRegistrationValidator.ValidationResult result = validator.apply(customer);</pre><h3>Conclusion</h3><p>The Combinator Pattern brings the power of functional programming to our validation logic. It allows us to write more flexible, maintainable, and expressive code. By breaking down complex validations into smaller, composable pieces, we can create validation logic that’s easier to understand, test, and modify.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bc01eb16705a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[JAVA VS Go]]></title>
            <link>https://medium.com/@prabin.neupane.work/java-vs-go-9db598a172d0?source=rss-2d8a6f406d2f------2</link>
            <guid isPermaLink="false">https://medium.com/p/9db598a172d0</guid>
            <category><![CDATA[java-vs-go]]></category>
            <dc:creator><![CDATA[Prabin Neupane]]></dc:creator>
            <pubDate>Wed, 07 Feb 2024 18:28:19 GMT</pubDate>
            <atom:updated>2024-02-07T18:28:19.262Z</atom:updated>
            <content:encoded><![CDATA[<p>JAVA VS GO</p><h3>1. Purpose and Use Cases:</h3><p>Java is a general-purpose language known for its &quot;write once, run anywhere&quot; mantra, making it suitable for developing applications that can run on any platform with the Java Virtual Machine (JVM).</p><p>Go (also known as Golang) is a statically typed, compiled language developed by Google. It&#39;s designed for simplicity, efficiency, and concurrency, making it a good choice for systems programming, cloud services, and web development.</p><h3>2. Syntax and Concurrency:</h3><p>Java has a more verbose syntax compared to Go, which is known for its simplicity and readability.</p><p>Go has built-in support for concurrency through goroutines and channels, making it easier to write concurrent programs compared to Java, which requires more explicit threading.</p><h3>3. Performance:</h3><p>Go is often praised for its performance and efficiency, especially in terms of concurrency and parallelism.</p><p>Java&#39;s performance can vary depending on the implementation (e.g., Oracle&#39;s JDK, OpenJDK), but it&#39;s generally considered to be a high-performance language, especially with modern JVM optimizations.</p><h3>4. Community and Ecosystem:</h3><p>Java has a large and mature ecosystem with extensive libraries, frameworks (e.g., Spring, Hibernate), and tools (e.g., Maven, Gradle) for various purposes.</p><p>Go&#39;s ecosystem is growing rapidly, but it&#39;s still smaller compared to Java. However, it has a strong standard library and is gaining popularity in areas like cloud-native development and microservices.</p><p>Choosing between Java and Go depends on your specific project requirements, familiarity with the language, performance considerations, and ecosystem support needed for your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9db598a172d0" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>