Presentation is loading. Please wait.

Presentation is loading. Please wait.

Hibernate Bayu Priyambadha, S.Kom.

Similar presentations


Presentation on theme: "Hibernate Bayu Priyambadha, S.Kom."— Presentation transcript:

1 Hibernate Bayu Priyambadha, S.Kom

2 What is Hibernate? It is an object-relational mapping (ORM) solution for Java We make our data persistent by storing it in a database Hibernate takes care of this for us

3 Object-Relational Mapping
It is a programming technique for converting object-type data of an object oriented programming language into database tables. Hibernate is used convert object data in JAVA to relational database tables.

4 Object/Relational Mapping
Presentation Layer Business Layer Persistence Layer Database 1. Data management tasks in object-oriented (OO) programming are typically implemented by manipulating objects that are almost always non-scalar values. Such as: user object group Object Model Relational Model

5 Why Hibernate and not JDBC?
JDBC maps Java classes to database tables (and from Java data types to SQL data types) Hibernate automatically generates the SQL queries. Hibernate provides data query and retrieval facilities and can significantly reduce development time otherwise spent with manual data handling in SQL and JDBC. Makes an application portable to all SQL databases.

6 Hibernate vs. JDBC (an example)
JDBC tuple insertion – st.executeUpdate(“INSERT INTO book VALUES(“Harry Potter”,”J.K.Rowling”)); Hibernate tuple insertion – session.save(book1);

7 Architecture Hibernate sits between your code and the database
Maps persistent objects to tables in the database

8 Hibernate Configuration
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" " <hibernate-configuration> <session-factory> <property name="hibernate.dialect"> org.hibernate.dialect.MySQLDialect </property> <property name="hibernate.connection.driver_class"> com.mysql.jdbc.Driver <property name="hibernate.connection.url"> jdbc:mysql://localhost:3306/buku <property name="hibernate.connection.username"> root <mapping resource="model/Buku.hbm.xml"/> </session-factory> </hibernate-configuration>

9 Hibernate Mapping <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" " <!-- Generated Apr 30, :17:25 PM by Hibernate Tools GA --> <hibernate-mapping> <class name="model.Buku" table="buku" catalog="buku"> <id name="bukuId" type="java.lang.Integer"> <column name="buku_id" /> <generator class="identity" /> </id> <property name="bukuJudul" type="string"> <column name="buku_judul" length="35" /> </property> <property name="bukuPengarang" type="string"> <column name="buku_pengarang" length="50" /> <property name="bukuPubliser" type="string"> <column name="buku_publiser" length="50" /> <property name="bukuTahun" type="string"> <column name="buku_tahun" length="4" /> </class> </hibernate-mapping>

10 SessionFactory (org.hibernate.SessionFactory)
The main contract here is the creation of Session instances. Usually an application has a single SessionFactory instance and threads servicing client requests obtain Session instances from this factory. A factory for Session

11 Session (org.hibernate.Session)
The main runtime interface between a Java application and Hibernate. This is the central API class abstracting the notion of a persistence service. A short-lived object Representing a conversation between the application and the database Wraps a JDBC connection Factory for Transaction

12 Thank You....


Download ppt "Hibernate Bayu Priyambadha, S.Kom."

Similar presentations


Ads by Google