Monday, July 19, 2021

Hibernate - 1

1. Overview of ORM and Hibernate

2. Mappings

  1. Simple
  2. Component
  3. Inheritance 
  4. Collections
  5. Association  

3. Object states in hibernate

4. HQL

5. Criteria


JDBC - Challenges

1. Creating and Closing the connection

2. Dependency - drivers and connection related code depends on the database - whenever DB changes, code needs to be change. For any change, table rename, column added, data type.. for any small change needs application change.

3. Exception handling

4. SQL challenges - for programmer ( programmers tend to low in SQL )

5. Data conversion 


ORM - Object Relational Mapping - In simple Map Object(fields) with Table (columns)

XML based

Annotations 

Hibernate - JPA specification - lies between Java Application and JDBC

Hibernate High Level View


Creating Application

Step 1 : Dependency 

    a. hibernate

     b. JDBC

Step 2: Entity or Persistent - java bean

Step 3: Mapping - contain bean and table ( no configuration on database )

     a.  XML 

      b. Annotations

Step 4: Database (hibernate config)

a. XML

b. properties

c. Programmatic

Step 5: Client - main application 


Step 1 : use spring initializer with adding Spring data JPA,  mysql (driver depends on DB)

Step 2: Create simple Java class and decorate with annotations. @Entity and @ID are important . If you do not use @Table, @Column automatically taken name of class as table name as fields as columns


Step 5: Where should the program start ? reading the configuration for DB. From configurations create Session factory (immutable singleton).Session factory is like a pool of connections.


In Code, lets' assume you have written code to read configuration and created SessionFactory. now execute code. Will tables get created. log will show dropping and creating tables.

No tables will be created. Why ? we have not made a session and create a object and set POJO to session and execute. Then hibernate will create a table, if not ( we are running on UPDATE, not CREATE)

Still new object will not be saved. Why ? 

By default - hibernate auto commit is disable.

Create a Transaction and commit after save(). you can see the INSERT statement. 



Friday, July 2, 2021

Docker Notes -1

 docker-compose down --rmi -all


how do we run two OS in one machine - Using Hypervisor


OS1  | OS2

----------

Hypervisor

-----------

Machine OS


Hypervisor : Virtual Box, VMVare, Hyper-v(only Windows)


Benifit creating Virtual machine

Run application in isolation

same application using different version

eg:

virtual Machine1{App1 with Node14, Mongo 4}

virtual Machine2{App2 with Node9, Mongo 3}


Problems with VMs

-----

Each machine needs full-blown OS (license)

Slow to start ( cause entire OS needs to start just as a normal machine)

Resource intensive ( takes certain Hardware - RAM, cpu ..)



Containers

-----

Allow running multiple apps in isolation(same kind of a isolation)

light weight

Use OS of the host ( share)

Start quickly ( OS already started)

need less hardware resources


so can run more containers compared to vms


docker run client - server architecture

client communicate using RESTApi

server --> docker engine


technically container is a process



basically all containers use kernal of the host
kernal - manages all applications and hardware