anchor.diff: -= Jpa and spring data kata
  += JPA/Hibernate camp
  +:docInfo1
  +:numbered:
  +:icons: font
  +:pagenums:
  +:imagesdir: images
  +:source-highlighter: coderay
  +
  +:image-link: https://pbs.twimg.com/profile_images/425289501980639233/tUWf7KiC.jpeg
  +
  +ifndef::sourcedir[:sourcedir: ./src/main/java/]
   
   #Sample demo to show how jpa work in effiecient way
   
  
positive.code:   - no argument constructor
    - getter and setter for all interested fields
    - 
  
  :source-highlighter: coderay
  
  [source,java]
  ----
  System.out.println("test code");
  ----
  
  
  
  
  
negative.code:      - OGM - support for NoSql database operation. Reusing Hibernate core engine to persistence and mapping nosql data.
       - Envers - audit logging and keeping multiple version. Allow to show history operation is also similar to version control system like svn or git
    
  * Hibernate benefits:
      - Productivity -> (metadate, query data, decrease development time -> productivity increase )
      - Prototyping  -> extremely useful for quick prototyping
      - Maintainability
      - Vendor independence
      
  * Hibernate disadventage
     - Learning curve
     - Overhead
     - Slower performance: For large batch updates, performance is slower.
     
     
  * SessionFactory
  * Opening and Closing Sessions
    represents a unit of work and is bound to the current thread
    It also represents a
   transaction in a database. A session begins when getCurrentSession() is first called on the current thread.
   The Session object is then bound to the current thread. When the transaction ends with a commit or
   rollback, Hibernate unbinds the session from the thread and closes it.   
   :source-highlighter: coderay
   [source,java]
  ----
   Session session = factory.openSession();
  try {
  // Using the session to retrieve objects
  }catch(Exception e)
  {
  e.printStackTrace();
  } finally {
  session.close();
  }
  ----
   
  Retrieving and Persisting Objects
  Book book = (Book) session.load(Book.class, isbn);    
    when the given ID can’t be found, the load() method throws an org.hibernate.ObjectNotFoundException exception
    he load() method just returns a proxy by default; the database  isn’t hit until the proxy is first invoked
    
  Book book = (Book) session.get(Book.class, isbn);
     get() method returns a null object
     get() method hits the database immediately
     
  The load() method is useful when you need only a proxy, not’ a database call. You need only a proxy in a given session  when you have to associate an entity before persisting.   
        
  * Using the JPA EntityManager
   [source,groovy]
  ----
  <dependency>
  <groupId>org.hibernate</groupId>
  <artifactId>hibernate-entitymanager</artifactId>
  <version>4.3.5.Final</version>
  </dependency>
  ----
  
  EntityManagerFactory has the same role as SessionFactory in Hibernate. It acts a factory class that
  provides the EntityManager class to the application.
  
  
  JTA is used in J2EE-managed applications in which the container is responsible for  transaction propagation.
  For application-managed transactions, you can use RESOURCE_LOCAL.
  
  
  Enabling Logging in Hibernate
  Inspecting the SQL Statements Issued by Hibernate <property name="show_sql">true</property>
  Enabling Live Statistics  <property name="hibernate.generate_statistics">true</property>      
        
  * Problem of subtypes
  
  * Simple entity
  