Posts

JPA mappedBy and JoinColumn

Image
In database we have a foreign key.  In simple foreign key establish the relationship between two database tables. Primary key of one table is placed into another table.  That key is called  foreign key. Here can have a book table and author table . Every author is linked with those books which are written by him.  So inside the book there is author name. that reflect the relation.  In relationship database model. Author is identified by his unique identification, This is the primary key of author table.  Book table will contain the identification of author. Book table have author id and this foreign key is not unique in book table. One single author can write multiple books, @JoinColumn specifies the foreign key column is the Book table that links to the Author entity. In this case, it's author_id. A n example of how to use @JoinColumn annotation with @ManyToOne and @OneToMany relationships in JPA. Consider two entities Author and Book , where an author...

Enum private Constructor

enum has constructor. This constructor is private. Why do we need a private constructor? because enum has finite values.  If the constructor is public , anyone can change the values of enum. It can increase the values  This would extend the initial values of enum.  It is a compile time error if the constructor of an enum type is declared as public or protected.  If no access modifier is specified for the constructor of an enum type, The constructor is by default private. package com.simple   public enum  BankAccount    {      AXIS  ("Axis Bank Account"),     DENA  ("Dena Bank Account"),     HDFC  ("Hdfc Bank Account");     private final String desc ;     BankAccount    ( String   desc) {        this.desc = desc;       }     public String getDesc(){       return desc;    } Here we have a Ba...

Predicate The Functional interface in java

What is a functional interface?  A Functional Interface is an Interface which allows only one abstract method within the interface scope. To use a normal interface there are two steps. 1. Declare one interface with abstract method. 2. Provide  body of Interface  by implementing on a class. Same happen in case of functional interface. Important difference in functional interface there is only one abstract method declaration. While implementing we use the benefit of single abstract method , we write anonymous function for single abstract method. This functional interface helps us to write lambda in java. public interface MyFunctionalnterface < T > { String funPart (T t) ; } public class UseFunctional { public static void main(String [] arg) { String str =" Functional World !"; M yFunctionalnterface<String> callFun; callFun= (xyz)-> { return str + xyz; }; System.out.println(callFun. funPart (" in java ")); } } Som...