Posts

Top 50 Hibernate Interview Questions and Answers - Frequently Asked - 2022

Image
1. What is Hibernate? Hibernate is the most popular open-source Java ORM framework in use today. Hibernate allows you to map plain old Java objects to relational database tables. Hibernate also provides data query and retrieval facilities. Hibernate generates the SQL calls and attempts to relieve the developer from manual result set handling and object conversion and keep the application portable to all supported SQL databases.  2. What is ORM? ORM sets the mapping between the set of objects which are written in the preferred programming language like Java and relational database like Oracle. It hides and encapsulates the SQL queries into objects and instead of SQL queries, we can use directly the objects to implement the SQL query. 3. What are the major advantages of Hibernate Framework? Hibernate framework is an open-source framework.  Hibernate framework is a high-performance framework because of its internal cache. Provides facilities to automatically create a table. It provides a

Unit testing Java HttpClient with MockWebServer from OkHttp

Image
Hello everyone, here you will learn unit testing Java HttpClient with MockWebServer from OkHttp. The  Source code download link is provided at the end of this tutorial. The HTTP Client was added in Java 11 onwards. It can be used to request HTTP resources over the network. It fortifies HTTP/1.1 and HTTP/2, both synchronous and asynchronous programming models, handles request and replication bodies as reactive-streams, and follows the familiar builder pattern. MockWebServer makes it possible to facilely test how our apps comport when making HTTP/HTTPS calls. A mock web server is a program that mocks the behaviour of an actual remote server but doesn't make calls over the internet world. Technologies Used: Java 17 OkHttp MockWebServer Maven 3+ jackson databinder Final project directory: Okhttp mockwebserver and jackson databinder dependencies <properties> <maven.compiler.target> 17 </maven.compiler.target> <maven.compiler.source> 17 </ma

How to transform HashMap to another HashMap using Java 8 Collectors toMap

Image
Hello everyone, here we will show you how to convert HashMap<Integer, User> to another HashMap<Integer, UserDto> using Java 8 Collectors toMap. The  Collectors.toMap returns a Collector that accumulates elements into a Map whose keys and values are the result of applying the provided mapping functions to the input elements. Overview of components used in this example Java Stream API The Java Stream API provides a functional approach to processing collections of objects. The Stream in Java can be defined as a sequence of elements from a source Collection or Array. Most of the stream operations return a Stream. This helps create a chain of stream operations(stream pipe-lining). The streams also support the aggregate or terminal operations on the elements. for example, finding the minimum or maximum element or finding average etc...Stream operations can either be executed sequentially or parallel. when performed parallelly, it is called a parallel stream. Collectors.toMap The