Download presentation
Presentation is loading. Please wait.
Published byGary Daniel Modified over 8 years ago
1
HIBERNATE/Java Overview of technology for Hibernate by محمد حسن کاظمی پوران Master : M.M.Nematollahi
2
Intro: About Hibernate www.hibernate.org - Open Source since, and now with JBoss (since late 2003) w/ commercial support & training. Founder: Gavin King Provides a layer for java to interact with the database. –Is technically a set of java-class libraries that you use to gain access to your database Hibernate caches database objects –& Hibernate services your Java program
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
What is Hibernate? It is open source object-relational mapping (ORM) for Java. Hibernate is responsible for making data persistent by storing it in a database.
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 as more time is required to manually handle data in SQL and JDBC. It makes an application portable to all SQL databases.
6
Architecture Hibernate sits between your code and the database Maps persistent objects to tables in the database
7
Hibernate Basics. SessionFactory – Is a factory which provides Session. Session – Single unit of work. Dirty checking Hibernate xml file – ‘.hbm’ It uses reflection
8
Hibernate Configuration A typical POJO class
9
Hibernate configuration Event.hbm.xml
10
hibenrate.hbm.xml
11
Singleton class to create SessionFactory object
13
Hibernate Configuration The hibernate.properties file –Used for hibernate configuration –Contains -Database configuration -Datasource configuration -Transaction configuration -Caching configuration -Connection pool configuration -Other settings
14
Hibernate Configuration... Contd The hibernate.cfg.xml –Alternative approach of configuration –Can be used as replacement of hibernate.properties –Picked up from classpath –Has got precedence on hibernate.properties file
15
Hibernate Configuration... Contd Non managed environment COM.ibm.db2.jdbc.app.DB2Driver jdbc:db2:SAMPLE db2admin 10 true net.sf.hibernate.dialect.DB2Dialect
16
Hibernate Configuration... Contd Managed environment (App Server) java:comp/env/jdbc/my_ds1 org.hibernate.transaction.CMTTransactionFactory org.hibernate.transaction.WebSphereExtendedJTATransactionLookup true org.hibernate.dialect.DB2Dialect
17
Hibernate Mapping The hibernate-mapping xml file
18
Use Hibernate in code Access the persistent objects just like you would any normal java POJO Use the dao operations (save, delete, etc.) to control the lifetimes of objects Take advantage of the Hibernate tools
19
Example App revisit Same basic structure –Alpha is the main class –Bravo handles user interaction –Charlie handles application logic –Delta handles data access New implementation of the Delta interface –UserString model class and hbm
20
Any questions? Hibernate: http://www.hibernate.org/http://www.hibernate.org/ Spring ORM http://www.springframework.org/docs/referen ce/orm.html
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.