1 / 5

Hibernate First Level Cache with Example

Caching is facility provided by ORM framework which help users to get fast running web application, while help framework itself to reduce number of quaries made to database in a single transaction. Hibernate achives the second goal by implementing first level cache.<br>First level cache is enabled by default and you can notdiasable it.<br>First level cache is associated with session object and other session objects in application can not see it.<br>The scope of session cache objects is of session. Once session is closed, cached object is gone forever.

Ducat1
Download Presentation

Hibernate First Level Cache with Example

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Welcome to Ducat India Apply Now Language | Industrial Training | Digital Marketing | Web Technology | Testing+ | Database | Networking | Mobile Application | ERP | Graphic | Big Data | Cloud Computing Call us: 70-70-90-50-90 www.ducatindia.com

  2. Hibernate First Level Cache with Example • Understanding Hibernate First Level Cache With Example. • Caching is facility provided by ORM framework which help users to get fast running web application, while help framework itself to reduce number of quaries made to database in a single transaction. Hibernate achives the second goal by implementing first level cache. • First level cache is enabled by default and you can notdiasable it. • First level cache is associated with session object and other session objects in application can not see it. • The scope of session cache objects is of session. Once session is closed, cached object is gone forever. • First level cache retrieval example • In this example, we are fetching student object from the database using a hibernate session. we will retrieve it multiple times and will observe the SQL logs to see the differences.

  3. packagenet.ducatindia.hibernate.tutorial; importorg.hibernate.Session; importorg.hibernate.Transaction; importnet.ducatindia.hibernate.tutorial.config.HibernateJavaConfig; importnet.ducatindia.hibernate.tutorial.entity.Student; publicclassFirstLevelCacheDemo { publicstaticvoidmain(String[] args) { Transactiontransaction=null; try (Sessionsession=HibernateJavaConfig.getSessionfactory().openSession()) { // start the transaction transaction=session.beginTransaction(); // get the student entity using id Student student1 =session.load(Student.class, newLong(1));

  4. System.out.println(student1.getFirstName()); System.out.println(student1.getLastName()); System.out.println(student1.getEmail()); // load student entity by id Student student2 =session.load(Student.class, newLong(1)); System.out.println(student2.getFirstName()); System.out.println(student2.getLastName()); System.out.println(student2.getEmail()); // commit transaction transaction.commit(); } catch (Exception e) { if (transaction !=null) { transaction.rollback(); } } } } Output: Read More: https://tutorials.ducatindia.com/java/hibernate-first-level-cache-with-example/

  5. Thank You Call us: 70-70-90-50-90 www.ducatindia.com

More Related