Friday, March 31, 2017

Difference between Get() and load() in Hibernate

      Difference between Get() and load()   ?

ses.get(-,-)
performs early/eager loading of the record that means it loads record from database table to object irrespective of whether that object is used in further part of the application or not

ses.load(-,-)
method performs lazy loading of the records that means Hibernate framework retrives the record from table to object only where the utilization of the object is started  till that it gives proxy object to application.




ses.get(-,-)
ses.load(-,-)
      1.       Performs eager loading of object
      2.       Does not generate proxy object
      3.       Involves total one object of domain class in the loading of record.
      4.       Suitable to check whether record is available of not  
      5.       Returns null value when record is not available
      6.       Useful for immediate and granted utilization of record once the record loaded.
      7.        Useful in single layer environment
        1.       Performs lazy loading of object
        2.       Generates proxy objects
         3.       Involves total two objects of domain        class (one real one proxy object) in the  loading of record.
        4.       We should use this method by assuming  record is available 
        5.       Throws ObjectNotFoundException when  record is not available.
       6.       Useful for delayed of non-granted  utilization of the record once the record is  marked.
       7.       Useful in multilayer environment where the record marked in one layer will be utilized in another layer.



     Diffrence between update() merge() and saveorupdate() ?



ses.update(-)
ses.saveOrUpdate(-)
ses.merge(-)
      1.       Perform object updating/record updating 
      2.       Updating record without checking the availability of the record.
     3.       Generates only update query
     4.       Generates update query even through object data is matching that is available in the table.
      5.       Does not return any object representing the records that has to be updated.
      1.      Perform save/insert  of update operations on record
      2.      Update insert of updated the record by checking the availability of record.
      3.      Generates select query and insert/update query.
      4.      Does not generate update query.
      5.      Does not return any object representing the records that has to be updated.
      1.       Perform save/insert of update operations on record.
       2.       Update insert of updated the record by checking the availability of record
        3.       Generates select query and insert/update query.
4.       Does not generate update query.
        5.       Returns object representing the record that has to be updated of inserted

What is the difference between ses.save(-) and ses.persist(-) method in Hibernate

       What is the difference between ses.save(-) and ses.persist(-) method ?

ses.save(-) method gives instruction to hibernate framework to save object and also returns  the generated identity values back to java application where as ses.persist(-) does not return the dame identity value .

ses.save(-) method return type is “Serializable(I)”.

ses.persist(-) method return type is “void”.

Prototype :-

public void persist(Object obj)

What is the use of hibernate. Dialect property in Hibernate configuration file in Hibernate


What is the use of hibernate. Dialect property in Hibernate configuration file?

It is hibernate property that expects the api supplied sub class name of org.hibernate.dialect.Dialect class this class name will change based on the Database software and its version we use.

   Oracle 9i----à org.hibernate.Oracle9iDialect

   Oracle 10g----à org.hibernate.Oracle10gDialect


   Mysql5----à org.hibernate.dialect.Mysql5dialect

What is sessionFactory in Hibernate

        What is sessionFactory ?

        SessionFactory:- 


Factory to create hibernate session objects  Maintains the datea that is collected from configuration object(Both cfg file and mapping file data).

Represents JDBC Con  pool that is created based on cfg file data .
SessionFactory object is immutable that means the data of this object cannot be modified onc created.

It is the object of  java class that implementes org.hibernate.SessionFactory.

SessionFactory factory=cfg.buildSessonFactory();


Builds session factory object having inmemory metadata  of both xml files that is gathered throuth “cfg” object.that is created based on hibernate cfg properties of inmemory metadata. 

What is session in Hibernate

1.       What is session?

Session:-

Open the session/connection with database software from hibernate application.
Internally encapsulates the JDBC con that is collected from JDBC con pool represented by session factory object.
The main component in hibernate application to provide the form of objects Based  on  these instruction. Hibernate framework internally uses JDBC code with SQL Queries to perform persistence operations.
It is the object of java class that implements org.hibernate.Session(I).

Session session=factory.openSession();

Makes SessionFactory object to create 1 hibernate session object encapsulating the JDBC connection object  this session object is useful to maintain domain class objects and to  provide persistence instances of hibernate framework.

JDBC of Limitations

JDBC of  Limitations:-


  è JDBC code is based on sql queries and these queries are database software  dependent sql queries so jdbc code is database software dependent persistence.

  è Changing database software in the middle of project development or in the middle of project production is very complex.

  è Jdbc code is having boiler plate code problem (writing same code in multiple apps either as it is or with minor changers)

       Eg:- 

       The jdbc placed multiple apps reaming same except sql query execution and its result processing.

  è Exception handling is mandatory because it raises the checked exception is called sql exception.

  è The select sql query execution gives Resultset object which is not serializable object to send over the network.

  è We cannot use object directly in persistence operations even though we get data in the form objects i.e we need to convert object data into simple values to use in persistence operations.

  è There is no direct support for services like caching transaction management and etc.


To overcome most of these problems use O-R Mapping to developed the persistence logic. 

Features of Hibernate

1            Hibernate Features:-



Ø  Hibernate supports POJO/POJI model programing.

Ø  Hibernate is light weight.

Ø  Hibernate persistence logic is database independent i.e it is portable across the multiple Database software’s.

Ø  Gives database software independent query language called HQL(hibernate query language).

Ø  Provide caching/buffering support which holds database table records across the multiple same requests and reduces network round trips between java application and database software.

Ø  Gives built in JDBC connection pool and also allows to use third party JDBC con pool like C3p0,Proxool and server managed JDBC con pool.

Ø  Support Lazy loading.

Ø  Hibernate con load recorded from table into application not when code is executed but when the record   utilization is stared in the application this is called loading the record from DB table on demand basis.

Ø  Supports versioning
Allows to keep track of how many times the record is access and modify through hibernate persistence logic.

Ø  Supports Time stamping.
Allows to keep track of when the record is inserted / update through hibernate persistence logics (maintains date, time values).

Ø  Allows to create dynamic schema(database table creation dynamically)
Hibernate is capable of creating database table dynamic in new database software when the database software of the project’s changed dynamically.



Ø  Gives “Criteria API” to generate optimized SQL Queries.
Hibernate itself take the responsibility of generating best SQL query internally to give the good performance when  we work with  “Criteria API”.

Ø  Allows to develop objects based persistence logic.

Ø  Supports object based relationships like one-to-one,one-to-many,many-to-many,many-to-one and etc.

Ø  Easy to integrate with other java technology and java framework.

Ø  Exception handling is optional because hibernate exception are unchecked exception.

Ø  Allows to call pl/sql produres and functions.

Ø  Supports both xml based configurations and annotation based configurations.


Ø  Easy to learn and easy to use.

What is O-R Mapping in Hibernate






The process of java class with Database ,java class member variables with Database table columns and making the objects of java class representing database table records having synchronization between them is called O-R Mapping.


           The Synchronization between objects and database table row is nothing but the modification done in object will reflect in Database table and vice-versa. 

What is Hibernate Java High Q

Hibernate is an open source light weight non-invasive java  ORM Framework given by “SoftTree” (redHat) to developed objects based Database software independent O-R Mapping persistence logic in all kinds of java Applications 

Thursday, March 30, 2017

Interface vs abstract class vs concrete class in java

Interface vs abstract class vs concrete class:-
Interface:-
If we don’t know anything about implementation just we have requirement specification then we should go for interface.
Ex:-  Servlet, Collection
Abstract class:-
If we are taking about implementation but not completely (partial implementation) then we should go for abstract class.
Ex:-
 GenericServlet (AC), HTTPServlet (AC)
Concrete class:-
If we are taking about implementation completely and ready to provide service then we should go for concrete class.
Ex:-




Difference between interface and Abstract class in java


Difference between interface and Abstract class in java




                                           Interface
Abstract class
a)      If we don’t know anything about implementation and just we have requirements speciation then we should go for interface.
A )If we are taking about implementation but not completely   (partial implementation) then we should go for abstract class.
b)     Inside interface every method is always public and abstract weather we are declaring or not hence interface is considered as 100 % pure abstraction.
B)Every method present inside abstract class need not be public and abstract and we can take concrete method also
c)                 As every interface method is always public and abstract and hence we can’t declare with the following modifiers
private,protected,final,static,synchronized,naticeand strictfp
C) These are no restrictions on abstract class method modifiers.
d)     Every variable present inside interface is always public static final weather we are declaring or not
D ) every variable present inside abstract class need not be public static final
e)      As every interface is always public static final we can’t declare with the following modifiers private, protected ,volatile & transient modifiers
E ) these are no restrictions on abstract class variable modifiers
f)       For interface variables compulsory we should perform initialization at her time of declaration only otherwise we will get compile time error
F ) For abstract class variable we are not required to perform initialization at the time of declaration.
g)      Inside interface we cannot declare static and instance  blocks
G )inside abstract class we can declare static & instance blocks

h)     Inside interface we cannot declare constructors
H )Inside abstract class we can declare  constructor