There are three types of inheritance mapping strategies − Table per class hierarchy Table per concrete class Table per subclassIn this article, we will discuss table per class hierarchy. Table per class hierarchy In this, only a single table is created for inheritance mapping. Disadvantages of this approach is that a lot of null values gets stored in the table. @Inheritance(strategy=InheritanceType.SINGLE_TABLE), @DiscriminatorColumn and @DiscriminatorValue are the annotations used in this strategy. @DiscriminatorColumn is used to create an additional column which is used to identify the hierarchy classes. Consider the following example to understand this − Steps ... Read More
In this article, we will see how we can execute batch insert/update in hibernate. Whenever we execute a sql statement, we do it by making a network call to the database. Now, if we have to insert 10 entries to our database table, then we have to make 10 network calls. Instead we can optimize our network calls by using batching. Batching allows us to execute a group of SQL statements in a single network call. To understand and implement this, let us define our entities − @Entity public class Parent { @Id @GeneratedValue(strategy ... Read More
This tutorial will discuss how to write a Swift program to find the tangent of given radian value. A tangent function is used to define the ratio of the length of the opposite side to the adjacent side in the right-angled triangle. It is also known as the tan function. The mathematical representation of the tangent() function is − tan() = opposite side/adjacent Side In Swift, we can calculate the tangent of the given radian value using the pre-defined tan() function. This function returns the tangent value of the specified number. Here, the specified number represent an angle. Syntax ... Read More
Most of the time when we use JPA queries, the result obtained is mapped to an object/particular data type. But When we use aggregate function in queries, handling the result sometimes require us to customize our JPA query. Let’s understand this with help of an example (Department, Employee) − Dept.java @Entity public class Dept { @Id private Long id; private String name; @OneToMany(mappedBy = "dep") private List emp; //Getters //Setters } A department can have one or more ... Read More
In this article, we will see how we can connect to MySQL database using an ORM (object relational mapping) framework like hibernate. First of all, we need to add maven dependency for hibernate in our pom.xml file − org.hibernate hibernate-core 5.6.2.Final Now, let us define an entity class that will be mapped to a database table using hibernate. @Entity @Table( name = " Employee") public class Employee { @Id @GeneratedValue(strategy = GenerationType.AUTO) Long id; @Column(name = ... Read More
Caching helps to reduce database network call, for executing queries. First level cache is linked with a session. It is implemented implicitly. First level cache exist only till the session object is there. Once session object is terminated/closed, there will be no cache objects. Second level cache works across multiple sessions objects. It is linked with a session factory. Second level cache objects are available to all the session in a single session factory. These cache objects are terminated when that particular session factory is closed. Implementing second level caching We need to add the following dependencies in order to ... Read More
This tutorial will discuss how to write a Swift program to find the area of the rectangle. A rectangle is a quadrilateral or a closed two-dimensional shape with four sides. All the angles of a rectangle are equal (90 degrees) and the opposite sides are equal and parallel with each other.The area of the rectangle is known as the total space enclosed inside the boundaries of the rectangle. We can calculate the area of the rectangle by multiplying the length and width. Formula for Area of Rectangle Following is the formula for the area of the rectangle − Area = ... Read More
In this tutorial, we will learn how to print the prime numbers from 1 to N where N the value of N will be as an input from the user. Just a short brief about Prime numbers is that the Prime numbers are something which can be only divisible by 1 or itself. In this tutorial, we are going to discuss two approaches one which will take O(N^2) of time and the other will take O(N*log(logN)). Method 1 Time Complexity: O(N^2) Space Complexity: O(1) Algorithm STEP 1 − Declaring the number N of type int32 STEP 2 − Take ... Read More
In this tutorial, we will see how to get the input from the user in Golang. Golang has a library that consists of an input/output function which helps in printing and taking the output. The function to take the input is Scanln(). Algorithm For Taking Integer Input with User STEP 1 − We are importing the fmt package that has the input/output functions. STEP 2 − We are declaring a variable after that we are printing the lines to ask the user to give the input STEP 3 − Then using fmt.Scanln() we are taking the input and storing ... Read More
In this tutorial, we will discuss swapping two numbers in Golang. We will cover two approaches: first swapping two numbers within the function and second creating a different function. Swapping two numbers within the function Algorithm STEP 1 − Defining the variables that we want to Swap. STEP 2 − Initializing the variables. STEP 3 − Swapping the two variables within the function. STEP 4 − Print the variables after swapping. Example package main // fmt package provides the function to print anything import "fmt" func main() { // define the variables we ... Read More