<?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 Pranay Gaikwad on Medium]]></title>
        <description><![CDATA[Stories by Pranay Gaikwad on Medium]]></description>
        <link>https://medium.com/@pranaygaikwad?source=rss-e9bf66a64017------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3pWOeA3-nYnaQOfj</url>
            <title>Stories by Pranay Gaikwad on Medium</title>
            <link>https://medium.com/@pranaygaikwad?source=rss-e9bf66a64017------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 08:50:31 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pranaygaikwad/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[Spring Framework Architecture]]></title>
            <link>https://medium.com/@pranaygaikwad/spring-framework-architecture-87fef80daaa9?source=rss-e9bf66a64017------2</link>
            <guid isPermaLink="false">https://medium.com/p/87fef80daaa9</guid>
            <category><![CDATA[spring-architecture]]></category>
            <category><![CDATA[spring-framework]]></category>
            <dc:creator><![CDATA[Pranay Gaikwad]]></dc:creator>
            <pubDate>Thu, 02 Mar 2023 17:41:59 GMT</pubDate>
            <atom:updated>2023-03-02T17:41:59.052Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>Overview:</strong></p><ul><li>The <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/overview.html#overview"><strong>Spring framework</strong></a> is a widely-used open-source Java framework that provides a comprehensive programming and configuration model for building enterprise applications. Its architecture is designed around two core principles: <a href="https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/beans.html">Dependency Injection (DI)</a> and <a href="https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/aop.html">Aspect-Oriented Programming (AOP)</a>.</li><li>The <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/overview.html#overview"><strong>Spring framework</strong></a> consists of several modules, which can be categorized into four main areas: Core Container, Data Access/Integration, Web, and Miscellaneous. The Core Container provides the fundamental functionality of the Spring framework, including the IoC container and ApplicationContext. The Data Access/Integration area provides support for integrating with databases and other data sources. The Web area provides support for building web applications, including the Spring MVC and Spring WebFlux modules. The Miscellaneous area includes other modules that provide additional functionality, such as the Spring Security module for authentication and authorization features.</li><li><a href="https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/beans.html"><strong>Dependency Injection (DI)</strong></a> is a design pattern that helps to reduce the coupling between the components of an application. By using DI, the Spring framework enables loose coupling between components, making the application more modular and easier to maintain. The Spring framework provides an Inversion of Control (IoC) container, which is responsible for creating and managing instances of JavaBeans, and the ApplicationContext, which provides a unified view of the entire application configuration.</li><li><a href="https://docs.spring.io/spring-framework/docs/3.2.x/spring-framework-reference/html/aop.html"><strong>Aspect-Oriented Programming (AOP)</strong></a> allows developers to modularize cross-cutting concerns, such as logging, security, and transaction management, and apply them to multiple components of an application. This results in a more modular and reusable codebase. The Spring framework provides an AOP framework, which is responsible for managing cross-cutting concerns in the application, such as logging, security, and transaction management.</li><li>Overall, the Spring framework architecture is based on the principles of modularity, separation of concerns, and flexibility, providing developers with a powerful set of tools to build robust, scalable, and maintainable enterprise applications. The framework’s modular architecture allows developers to select only the necessary modules for their specific needs, reducing unnecessary overhead and complexity in the application. Additionally, the Spring framework’s flexible configuration model allows developers to configure the application using various approaches, such as XML-based configuration, Java-based configuration, and annotation-based configuration.</li></ul><p><strong>Spring Modules:</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*eVVZXiDZ_CSj7tW1.png" /></figure><ul><li>The Spring framework is modular and consists of several modules that provide different functionalities to help build enterprise applications. The modules can be broadly categorized into four main areas: <strong>Core Container, Data Access/Integration, Web, and Miscellaneous.</strong> Let’s take a closer look at each area and its corresponding modules:</li></ul><ol><li><strong>Core Container:</strong></li></ol><ul><li>The <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/core.html#spring-core"><strong>Core Container </strong></a>provides the fundamental functionality of the Spring framework, including the Inversion of Control (IoC) container and the ApplicationContext. It includes the following modules:</li><li><strong>Spring Core: </strong>This module provides the fundamental functionality of the Spring framework, including IoC and DI. The IoC container is the heart of the Spring Framework, responsible for creating and managing instances of JavaBeans. It uses dependency injection to wire the beans together.</li><li><strong>Spring Beans:</strong> This module provides the BeanFactory, which is the basic building block of the IoC container, and the BeanWrapper, which is responsible for managing the lifecycle of a bean. The Bean Factory is the core interface for accessing the IoC container. It provides methods for retrieving beans.</li><li><strong>Spring Context:</strong> This module provides the ApplicationContext, which is an advanced version of the BeanFactory and provides additional features, such as internationalization and resource loading,and the ability to publish and consume events.</li><li><strong>Spring Expression Language (SpEL):</strong> This module provides a powerful expression language for querying and manipulating objects during runtime. SpEL supports a wide range of features, including property access, method invocation, conditionals, loops, and type conversion. It also provides support for accessing variables and functions defined in the application context, as well as support for defining custom functions and variables.</li></ul><p>2. <strong>Data Access/Integration:</strong></p><ul><li>The <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/data-access.html#spring-data-tier"><strong>Data Access/Integration</strong></a> area provides support for integrating with databases and other data sources. It includes the following modules:</li><li><strong>Spring JDBC:</strong> This module provides a simple JDBC abstraction layer that reduces the amount of boilerplate code required to work with JDBC. Spring JDBC provides support for transaction management, allowing developers to manage database transactions declaratively using Spring’s transaction management.</li><li><strong>Spring ORM: </strong>This module provides integration with Object-Relational Mapping (ORM) frameworks, such as Hibernate and JPA. Spring ORM provides a higher-level abstraction layer on top of ORM frameworks, allowing developers to write less boilerplate code and more easily integrate ORM technologies with other Spring features, such as transaction management and caching.</li><li><strong>Spring Data: </strong>This module provides a consistent and easy-to-use programming model for working with data access technologies, including databases, NoSQL, and cloud-based data services. Spring Data provides a wide range of features, including automatic CRUD (Create, Read, Update, Delete) operations, query generation from method names, support for pagination and sorting, integration with Spring’s transaction management, and more. Additionally, Spring Data provides support for common data access patterns, such as repositories and data access objects (DAOs).</li><li><strong>Spring Transaction: </strong>This module provides support for declarative transaction management in Spring applications. Spring Transaction provides support for various transaction propagation and isolation levels, allowing developers to manage transactions at different levels of granularity. Additionally, Spring Transaction provides support for different transaction management strategies, such as using a JTA transaction manager or a simple JDBC transaction manager.</li></ul><p>3. <strong>Web:</strong></p><ul><li>The <a href="https://docs.spring.io/spring-framework/docs/current/reference/html/web.html#spring-web"><strong>Web</strong></a> area provides support for building web applications. It includes the following modules:</li><li><strong>Spring MVC:</strong> This module provides a Model-View-Controller (MVC) framework for building web applications. Spring MVC provides a range of features, including support for handling HTTP requests and responses, form handling, data binding, validation, and more. It also provides support for different view technologies, such as JSP (JavaServer Pages), Thymeleaf, and Velocity, allowing developers to choose the view technology that best suits their needs.</li><li><strong>Spring WebFlux: </strong>This module provides a reactive programming model for building web applications that require high concurrency and scalability. Spring WebFlux provides support for building reactive web applications using a range of technologies, such as Netty, Undertow, and Servlet 3.1+ containers. It also provides a range of features, including support for reactive data access, reactive streams processing, and reactive HTTP clients.</li><li><strong>Spring Web Services:</strong> This module provides support for building SOAP-based and RESTful web services. Spring Web Services provides support for generating WSDL (Web Services Description Language) from Java classes, and for generating Java classes from WSDL. This allows developers to define the contract (i.e., the interface) of their web service using WSDL, and to generate the Java classes that implement the web service from the WSDL.</li></ul><p><strong>4. Miscellaneous:</strong></p><ul><li>The Miscellaneous area includes other modules that provide additional functionality, such as:</li><li><strong>Spring Security: </strong>This module provides authentication and authorization features for Spring applications. Spring Security provides a range of authorization mechanisms, such as role-based access control and expression-based access control. It also provides support for securing different parts of the application using different security configurations, allowing developers to apply fine-grained security policies.</li><li><strong>Spring Integration:</strong> This module provides support for building message-driven and event-driven architectures. Spring Integration provides a range of integration patterns, such as messaging, routing, and transformation. It provides support for a range of messaging systems, such as JMS, AMQP, and Apache Kafka. It also provides support for integrating with different protocols, such as FTP, HTTP, and TCP.</li><li><strong>Spring Batch: </strong>This module provides support for batch processing and integration with enterprise systems. Spring Batch provides a range of tools and utilities for building and managing batch processing applications, such as support for testing and debugging batch jobs, logging and monitoring, and integration with other Spring modules, such as Spring Data and Spring Integration.</li><li><strong>Spring Cloud:</strong> This module provides support for building cloud-native applications using Spring technologies. Spring Cloud provides a range of features for building cloud-native applications, such as service discovery, configuration management, and load balancing. It provides support for integrating with different cloud platforms, such as AWS and GCP, and for using different cloud-native technologies, such as containers and serverless computing.</li></ul><blockquote><strong>Overall, the Spring framework modules provide developers with a powerful set of tools to build robust, scalable, and maintainable enterprise applications. The modular architecture of the Spring framework allows developers to select only the necessary modules for their specific needs, reducing unnecessary overhead and complexity in the application.</strong></blockquote><p><strong>Conclusion:</strong></p><ul><li>In conclusion, the Spring framework is a powerful and popular open-source Java framework that provides a comprehensive programming and configuration model for building enterprise applications. Its architecture is designed around the principles of modularity, separation of concerns, and flexibility, providing developers with a powerful set of tools to build robust, scalable, and maintainable enterprise applications.</li><li>I hope this article has been informative and helpful to you. Thank you for reading, and feel free to share this article with others who may find it useful.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87fef80daaa9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction of Spring Framework and Hibernate ORM]]></title>
            <link>https://medium.com/@pranaygaikwad/introduction-of-spring-framework-and-hibernate-orm-34f94c071ebf?source=rss-e9bf66a64017------2</link>
            <guid isPermaLink="false">https://medium.com/p/34f94c071ebf</guid>
            <category><![CDATA[spring-framework]]></category>
            <category><![CDATA[hibernate-tutorial]]></category>
            <category><![CDATA[spring-training]]></category>
            <dc:creator><![CDATA[Pranay Gaikwad]]></dc:creator>
            <pubDate>Wed, 01 Mar 2023 17:19:16 GMT</pubDate>
            <atom:updated>2023-03-01T17:19:16.999Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*Lh8P8UNspNK4Gw3EE2v-Hg.jpeg" /><figcaption>Spring</figcaption></figure><p><strong>Introduction:</strong></p><ul><li><a href="https://spring.io/projects/spring-framework"><strong>Spring Framework</strong></a><strong> </strong>is an open-source Java framework that is used to develop enterprise-level applications. It provides a wide range of features and functionalities such as inversion of control (IoC), dependency injection (DI), aspect-oriented programming (AOP), and more. These features help developers to build robust, scalable, and maintainable applications.</li><li><a href="https://hibernate.org/"><strong>Hibernate ORM (Object Relational Mapping)</strong></a><strong> </strong>is a popular Java-based framework used for mapping an object-oriented domain model to a relational database. It provides an efficient way of storing and retrieving data from a database by mapping database tables to Java classes and vice versa.</li><li>Spring framework provides a comprehensive programming and configuration model for modern Java-based enterprise applications — on any kind of deployment platform. A key element of Spring is infrastructural support at the application level: Spring focuses on the “plumbing” of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.</li><li>Spring Framework and Hibernate ORM are often used together to develop enterprise-level applications. Hibernate provides an efficient way of storing and retrieving data from a database, while Spring Framework provides features such as IoC, DI, and AOP to make the development process more organized and efficient.</li></ul><blockquote><strong>Note : </strong>Together, these two frameworks make it easy to develop complex applications with ease. Developers can leverage the features of both frameworks to build robust, scalable, and maintainable applications quickly and easily.</blockquote><p><strong>Spring Framework:</strong></p><ul><li>The Spring Framework architecture is designed to facilitate the development of enterprise-level applications by providing a modular and extensible approach to application development. The architecture is divided into several modules, each with specific functionality.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zyZcPykwYGNAMcNVnBJ9Vg.png" /><figcaption>Spring-modules</figcaption></figure><ol><li><strong>Core Container:</strong> This module provides the foundation of the Spring Framework. It includes the core components such as the BeanFactory, which is responsible for managing the lifecycle of objects in the application, and the ApplicationContext, which provides advanced features such as support for internationalization and environment-specific configuration.</li><li><strong>AOP:</strong> This module provides support for Aspect-Oriented Programming (AOP). AOP is a programming paradigm that enables developers to modularize cross-cutting concerns, such as security and transaction management, and apply them across the application.</li><li><strong>Data Access/Integration: </strong>This module provides support for data access and integration with various data sources such as databases, message queues, and web services. The module includes support for JDBC, Hibernate, JPA, and other data access technologies.</li><li><strong>Web: </strong>This module provides support for web application development. It includes support for building web applications using Spring MVC, which is a powerful and flexible web framework. It also includes support for web services, RESTful services, and WebSocket.</li><li><strong>Test:</strong> This module provides support for testing Spring applications. It includes support for writing unit tests, integration tests, and functional tests.</li></ol><p><strong>Hibernate Framework:</strong></p><ul><li>Hibernate ORM (Object Relational Mapping) is a popular Java-based framework used for mapping an object-oriented domain model to a relational database. It provides an efficient way of storing and retrieving data from a database by mapping database tables to Java classes and vice versa.</li><li><strong>Features of Hibernate ORM:</strong></li></ul><ol><li><strong>Object-Relational Mapping:</strong> Hibernate ORM provides support for mapping Java classes to database tables and vice versa. This allows developers to work with objects rather than low-level SQL statements.</li><li><strong>Lazy Loading:</strong> Hibernate ORM provides support for lazy loading, which is a technique for loading objects on demand rather than loading them all at once. This can help to improve performance and reduce memory usage.</li><li><strong>Caching: </strong>Hibernate ORM provides support for caching, which is a technique for storing frequently accessed data in memory. This can help to improve performance and reduce the number of database queries.</li><li><strong>Transactions: </strong>Hibernate ORM provides support for transactions, which are a mechanism for ensuring data consistency and integrity. Transactions can be used to group a set of database operations into a single atomic unit of work.</li><li><strong>Query Language:</strong> Hibernate ORM provides support for HQL (Hibernate Query Language), which is a powerful and flexible query language for querying objects. HQL is similar to SQL but operates on objects rather than tables.</li></ol><ul><li><strong>Advantages of using Hibernate ORM Framework:</strong></li></ul><ol><li><strong>Simplifies Database Operations:</strong> Hibernate ORM simplifies database operations by providing an easy-to-use API for storing and retrieving data from the database. This reduces the amount of boilerplate code required to interact with the database.</li><li><strong>Improves Performance:</strong> Hibernate ORM provides support for caching, which improves application performance by reducing the number of database queries. It caches frequently accessed data in memory, which reduces the time taken to access the data from the database.</li><li><strong>Platform Independence:</strong> Hibernate ORM is platform-independent, which means it can be used with any relational database. This provides flexibility and makes it easy to switch databases without changing the code.</li><li><strong>Open-Source: </strong>Hibernate ORM is an open-source framework, which means it is freely available and can be used by anyone. This reduces the cost of development and makes it easy to get started with Hibernate ORM.</li></ol><p><strong>Conclusion:</strong></p><ul><li><strong>Spring Framework is a powerful and flexible Java framework</strong> that provides a wide range of features and functionalities for developing enterprise-level applications. Its ease of use, performance, platform independence, and open-source nature make it an ideal choice for developers looking to build robust, scalable, and maintainable applications quickly and easily.</li><li><strong>Hibernate ORM is a powerful and popular framework for mapping object-oriented models</strong> to relational databases. It provides a wide range of features and functionalities that simplify database operations, improve performance, and provide platform independence. Hibernate ORM is widely used in enterprise-level applications and is a must-have skill for Java developers.</li></ul><p><strong>Thanks for reading this article so far. If you like this article and these Java best practices from Spring Framework then please share it with your friends and colleagues. If you have any questions or feedback then please drop a note….</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34f94c071ebf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[@Embeddable and @Embedded annotations in Hibernate]]></title>
            <link>https://medium.com/@pranaygaikwad/embeddable-and-embedded-annotations-in-hibernate-462be4a7141a?source=rss-e9bf66a64017------2</link>
            <guid isPermaLink="false">https://medium.com/p/462be4a7141a</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[hibernate]]></category>
            <category><![CDATA[java]]></category>
            <dc:creator><![CDATA[Pranay Gaikwad]]></dc:creator>
            <pubDate>Sun, 15 Jan 2023 11:46:46 GMT</pubDate>
            <atom:updated>2023-01-15T11:48:05.955Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*Lh8P8UNspNK4Gw3EE2v-Hg.jpeg" /><figcaption>Spring-hibernate</figcaption></figure><p><strong>Introduction:</strong></p><p>The <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embeddable.html"><strong>@Embeddable</strong></a> and <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embedded</strong></a> annotations in Hibernate are used to map an object’s properties to columns in a database table. These annotations are used in combination to allow the properties of one class to be included as a value type in another class and then be persisted in the database as part of the containing class.</p><p><strong>Overview:</strong></p><ul><li>The <strong>@</strong><a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embeddable.html"><strong>Embeddable</strong></a> annotation is used to mark a class as being embeddable, meaning its properties can be included in another class as a value type. The class marked with @Embeddable is called the embeddable class.</li><li>The <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embedded</strong></a> annotation is used to mark a field in a class as being an embeddable object, and it is used in the class that contains the embeddable object.</li><li>By using these annotations, Hibernate can automatically persist the properties of the embeddable class within the containing class to the database table, without the need to create a separate table for the embeddable class.</li><li>Using <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embeddable.html"><strong>@Embeddable</strong></a><strong> </strong>and<strong> </strong><a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embedded </strong></a>annotations in Hibernate, allows for better data modeling, code reusability, normalization, and better performance. The annotations also allow to encapsulate the business logic within the embeddable class.</li></ul><p><strong>Benefits:</strong></p><p>The main benefits of using the <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embeddable.html"><strong>@Embeddable</strong></a> and <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embedded</strong></a> annotations in Hibernate are:</p><ol><li><strong>Code Reusability:</strong> You can reuse the embeddable class in multiple entities, avoiding duplication of code.</li><li><strong>Normalization:</strong> It helps in normalizing the database by reducing the number of tables, which in turn improves the performance.</li><li><strong>Data Integrity:</strong> It ensures data integrity by maintaining the relationship between the embeddable and the containing class.</li><li><strong>Simplicity:</strong> It simplifies the development process by reducing the number of classes and tables required to map the data.</li><li><strong>Better Data Modelling:</strong> It allows for better data modeling by allowing you to encapsulate the properties of an object within another object, making the data structure more intuitive and easy to understand.</li><li><strong>Ease of maintenance:</strong> it makes the maintenance of the codebase more manageable and easy.</li><li><strong>Flexibility:</strong> The embeddable classes can be used in multiple entities, and it also support complex data modeling with the use of <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html">@Embedded</a> and <a href="https://docs.oracle.com/javaee/7/api/javax/persistence/AttributeOverrides.html">@AttributeOverrides</a>.</li><li><strong>Readability:</strong> The use of <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embeddable.html">@Embeddabl</a>e and <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html">@Embedded</a> annotations makes the code more readable and self-explanatory.</li><li><strong>Performance:</strong> it improves the performance of the application by reducing the number of joins required to fetch the data.</li><li><strong>Business logic:</strong> It allows to encapsulate the business logic within the embeddable class, making it more manageable and easy to understand.</li></ol><p><strong>Example:</strong></p><p><strong>Here is an example of how to use the </strong><a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embeddable.html"><strong>@Embeddable</strong></a><strong> and </strong><a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embedded</strong></a><strong> annotations in Hibernate:</strong></p><ul><li><strong>Embeddable Class:</strong></li></ul><pre>@Embeddable<br>public class Address {<br>    private String street;<br>    private String city;<br>    private String state;<br>    private String zip;<br>    //getters and setters<br>}</pre><ul><li><strong>Entity Class:</strong></li></ul><pre>@Entity<br>public class Employee {<br>    @Id<br>    private int id;<br>    private String name;<br>    @Embedded<br>    private Address address;<br>    //getters and setters<br>}</pre><ul><li><strong>In this example</strong>, the Address class is marked as <a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embeddable</strong></a>, which means it can be included as a value type in another class. The Employee class has an Address field which is marked with the<strong> </strong><a href="https://docs.jboss.org/hibernate/jpa/2.1/api/javax/persistence/Embedded.html"><strong>@Embedded</strong></a> annotation. This tells Hibernate that the Address object is an embeddable object and its properties should be mapped to columns in the same table as the Employee class.</li><li>When the Employee object is saved to the database, the properties of the embedded Address object will also be saved to the same table, with the column names being prefixed with the name of the field in the Employee class (in this case, “address_”).</li></ul><blockquote><strong>You can also use the </strong><a href="https://docs.oracle.com/javaee/7/api/javax/persistence/AttributeOverrides.html"><strong>@AttributeOverrides</strong></a><strong> to customize the column name mapping.</strong></blockquote><pre>@Embedded<br>@AttributeOverrides({<br>    @AttributeOverride(name = &quot;street&quot;, column = @column(name = &quot;home_street&quot;))<br>    })<br>    private Address address;</pre><blockquote><strong>The above example will map the street property of the Address class to home_street in the database table.</strong></blockquote><p><strong>Conclusion:</strong></p><ul><li><strong>embeddable</strong> and <strong>embedded</strong> annotations are useful tools in both web development and Hibernate for adding additional information and context to a piece of content or defining the relationship between entities in an ORM configuration. They allow for better organization and reuse of complex value objects, making the code more maintainable and efficient.</li><li>It’s important to understand the difference and use case of these annotations in order to effectively utilize them in your projects. Whether you are creating an educational website, a research paper or a professional software, embeddable and embedded annotations can help to enhance the user experience and understanding of the content.</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=462be4a7141a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Hibernate : Fetch Types]]></title>
            <link>https://medium.com/@pranaygaikwad/spring-hibernate-fetch-types-e9e53afebb25?source=rss-e9bf66a64017------2</link>
            <guid isPermaLink="false">https://medium.com/p/e9e53afebb25</guid>
            <dc:creator><![CDATA[Pranay Gaikwad]]></dc:creator>
            <pubDate>Sun, 08 Jan 2023 17:43:56 GMT</pubDate>
            <atom:updated>2023-01-08T17:43:56.050Z</atom:updated>
            <content:encoded><![CDATA[<h3>Spring Hibernate : Fetch Types</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/537/1*Lh8P8UNspNK4Gw3EE2v-Hg.jpeg" /><figcaption>Spring-Hibernate</figcaption></figure><p><strong>Introduction:</strong></p><p>FetchType is an enumerated type in the Java Persistence API (JPA) that specifies whether the field or property should be lazily loaded or eagerly loaded. It is used in the <a href="https://docs.oracle.com/javaee/6/api/javax/persistence/FetchType.html"><strong>javax.persistence.FetchType</strong></a> enum.</p><p>In Hibernate, the FetchType is used to specify the fetching strategy to be used for an association. The FetchType can be specified for associations at the time of mapping the association. There are two FetchType options available: <strong>LAZY and EAGER.</strong></p><figure><img alt="Fetch types" src="https://cdn-images-1.medium.com/max/413/1*NhzQkf-2OE90H7Ny65yj3A.png" /></figure><blockquote>You can specify the fetch type of an association by using the fetch attribute of the <strong>@OneToMany , @ManyToOne, @OneToOne, or @ManyToMany annotations</strong></blockquote><p><strong>1.LAZY:</strong></p><ul><li>This is the default FetchType in Hibernate. It means that the associated entity will be fetched only when it is accessed for the first time. This can improve performance in cases where the associated entity is not required most of the time.</li><li>This can be more efficient than eagerly fetching the entity, especially if the entity has a lot of data and is not needed for every use of the parent entity.</li><li><strong>Here is an example of how FetchType.LAZY can be used in a Hibernate @OneToOne mapping:</strong></li></ul><pre>@Entity<br>public class Employee {<br>  @OneToOne(fetch = FetchType.LAZY)<br>  @JoinColumn(name = &quot;address_id&quot;)<br>  private Address address;<br><br>  // other fields and methods<br>}</pre><blockquote><strong>In this example</strong>, the Address entity associated with an Employee will be fetched lazily when it is accessed for the first time.</blockquote><ul><li>It’s important to note that using <strong>FetchType.LAZY</strong> can result in additional database queries being issued when the associated entity is accessed, so it may not always be the most efficient option. It’s a good idea to profile your application to determine the best fetch strategy for your use case.</li></ul><p><strong>2.EAGER</strong></p><ul><li>This FetchType means that the associated entity will be fetched together with the main entity when the main entity is fetched from the database. This can be useful in cases where the associated entity is always required, but can also result in a performance decrease if the associated entity is large and/or has many associations itself.</li><li>The<strong> FetchType.EAGER</strong> option indicates that the associated entity should be fetched eagerly, which means that it will be fetched at the same time as the parent entity.</li><li><strong>Here is an example of how FetchType.EAGER can be used in a Hibernate @OneToOnemapping:</strong></li></ul><pre>@Entity<br>public class Employee {<br>  @OneToOne(fetch = FetchType.EAGER)<br>  @JoinColumn(name = &quot;address_id&quot;)<br>  private Address address;<br><br>  // other fields and methods<br>}</pre><blockquote><strong>In this example</strong>, the Address entity associated with an Employee will be fetched eagerly when the Employee is loaded from the database.</blockquote><ul><li>Using <strong>FetchType.EAGER</strong> can be more efficient than using FetchType.LAZY if the associated entity is needed for most uses of the parent entity, as it avoids the need for additional database queries to fetch the associated entity when it is accessed. However, it can also be less efficient if the associated entity has a lot of data and is not needed for every use of the parent entity, as it will always be fetched along with the parent entity. It’s a good idea to profile your application to determine the best fetch strategy for your use case.</li></ul><p><strong>Summary:</strong></p><ol><li>As I mentioned before, you must select the appropriate fetch type for your use case in order to prevent frequent Hibernate performance difficulties. The bulk of use cases calls for the fetch type. A good option is lazy.</li><li>Let’s quickly review the various fetch types. <a href="https://hibernate.org/"><strong>Hibernate</strong></a> is told to get the entities related to the initial query by EAGER fetching. Because only one query is required to retrieve all entities, this can be incredibly effective. However, most of the time you choose entities that are unnecessary for your use case, which results in significant overhead.</li><li>This is something that<strong> FetchType.LAZY </strong>may stop. This instructs Hibernate to postpone initialising the relationship until your business code has access to it. The negative aspect of this strategy.</li></ol><p>Thanks for reading.</p><p>#Hibernate, #Beginner, #SpringJPA, #Fetchtypes</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e9e53afebb25" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring Hibernate get() and load() methods]]></title>
            <link>https://medium.com/@pranaygaikwad/spring-hibernate-get-and-load-method-32a2a7e7161c?source=rss-e9bf66a64017------2</link>
            <guid isPermaLink="false">https://medium.com/p/32a2a7e7161c</guid>
            <category><![CDATA[java]]></category>
            <category><![CDATA[spring-boot]]></category>
            <category><![CDATA[load]]></category>
            <category><![CDATA[hibernate]]></category>
            <dc:creator><![CDATA[Pranay Gaikwad]]></dc:creator>
            <pubDate>Sun, 01 Jan 2023 17:10:26 GMT</pubDate>
            <atom:updated>2023-01-05T12:38:34.696Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/469/1*TzSe1lRcSJH2D3_12AjVAQ.jpeg" /></figure><p><strong>Introduction:</strong></p><p>Hibernate is a Java framework that provides a powerful set of tools for persisting and accessing data in a Java environment. It is often used in conjunction with Spring.</p><p>Spring and Hibernate are both widely used in the Java community, and they can be used together to build powerful and efficient Java-based applications.</p><p><strong>Let’s deal with Fetching objects in Spring Hibernate:</strong></p><p><strong>Hibernate</strong> provides different methods to fetch data from the database.</p><h4>1.get()</h4><h4>2.load()</h4><p><strong>Now, let’s start with the get() method</strong></p><ul><li><strong>get()</strong> method is used to retrieve a persistent object from the database. It is a member of the Session interface, and it takes the class of the object to be retrieved and the primary key of the object as arguments.</li><li><strong>get()</strong> method to retrieve a proxy object, which is a lightweight placeholder object that represents the persistent object but does not contain its data. The data is only loaded from the database when it is needed. This can be useful for optimizing performance when you only need to access a small part of an object’s data.</li><li>In <strong>the get()</strong> method, Hibernate will fetch the object’s data from the database if it has not already done so. This is known as “lazy loading.”</li><li><strong>Here is an example of how to use the get() method to retrieve an object:</strong></li></ul><pre>// Open a session<br>Session session = sessionFactory.openSession();<br><br>// Begin a transaction<br>Transaction transaction = session.beginTransaction();<br><br>// Retrieve the object using the primary key<br>Customer customer = (Customer) session.get(Customer.class, 1L);<br><br>// Commit the transaction<br>transaction.commit();<br><br>// Close the session<br>session.close();</pre><blockquote><strong><em>In this example, the get() method is used to retrieve a Customer object with a primary key of 1. The object is then cast to the Customer class and stored in the customer variable.</em></strong></blockquote><p><strong>Let’s have a look at load() method</strong></p><ul><li><strong>load()</strong> method is used to retrieve an object from the database by its identifier (primary key). It is used to initialize a proxy object instead of a fully-initialized object, so it can be used to lazily load the object when it is needed.</li><li><strong>load()</strong> method does not actually retrieve the object from the database when it is called. Instead, it returns a proxy object that represents the object. The actual object is only retrieved from the database when it is needed, such as when a method of the object is called or a property is accessed. This technique is known as “lazy loading” and it is used to improve the performance of Hibernate by avoiding unnecessary database queries.</li><li><strong>Here is an example of how the load() method might be used in Hibernate:</strong></li></ul><pre>Session session = sessionFactory.openSession();<br>Transaction transaction = session.beginTransaction();<br><br>// Load the entity with the identifier 1<br>Employee employee = (Employee) session.load(Employee.class, 1L);<br><br>// Print out the employee&#39;s name<br>System.out.println(employee.getName());<br><br>transaction.commit();<br>session.close();</pre><blockquote><strong><em>In this example, the load() method is used to retrieve a Employee object with a primary key of 1. The object is then cast to the Employee class and stored in the employee variable and print the employee object.</em></strong></blockquote><p>All the best to all of you. I hope you all understood the fetching objects topic in spring Hibernate. It just requires a lot of practice in the particular topic. Try to write code about spring Hibernate.</p><p>Hope you all have enjoyed this article. Happy learning!!!</p><p>#spring #Hibernate #Java #springboot</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32a2a7e7161c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>