Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is Object/relational mapping(ORM) in relation to Hibernate and JDBC?

Can someone explain, in layman terms, what is Object/relational mapping(ORM) in relation to Hibernate and JDBC?

Diagrams would be especially helpful for understanding...

EDIT: I found this via google for Hibernate ORM, can someone confirm that it is accurate and a good representation of how ORM is used.

enter image description here

src: http://software-carpentry.org/3_0/summary.html

like image 929
rrazd Avatar asked Aug 15 '11 16:08

rrazd


People also ask

What is object-relational mapping in hibernate?

What is ORM? ORM stands for Object-Relational Mapping (ORM) is a programming technique for converting data between relational databases and object oriented programming languages such as Java, C#, etc.

What is ORM object-relational mapping and it's working?

Object–relational mapping (ORM, O/RM, and O/R mapping tool) in computer science is a programming technique for converting data between type systems using object-oriented programming languages. This creates, in effect, a "virtual object database" that can be used from within the programming language.

What is ORM and JDBC?

ORM sits in between your application and JDBC providing the missing link between the object oriented model and relational database model of programming. In fact this so called ORM interacts with the JDBC to talk to the database ultimately.

What is meant by object-relational mapping?

Object-relational mapping (ORM) is a mechanism that makes it possible to address, access and manipulate objects without having to consider how those objects relate to their data sources.


2 Answers

ORM allows you to use java objects as representation of a relational database. It maps the two concepts (object-oriented and relational)

Hibernate is an ORM framework - you describe how your objects are represented in your database, and hibernate handles the conversion.

JDBC is the API for database access, and it works "in a relational way" - you query tables and get rows and columns back. Hibernate uses JDBC under the hood to fetch the data and later convert it to objects.

A jdbc ResultSet has multiple records, and each record has a set of columns. In hibernate this becomes of List<SomeClass> where SomeClass has a field for every column in the database table, and there is one instance ofSomeClass` per database record.

like image 112
Bozho Avatar answered Sep 30 '22 18:09

Bozho


I was reading on Hibernate and stumbled across this thread. Doing further research, I found this other great explanation which may help someone:

Hibernate framework simplifies the development of java application to interact with the database. Hibernate is an open source, lightweight, ORM (Object Relational Mapping) tool.

An ORM tool simplifies the data creation, data manipulation and data access. It is a programming technique that maps the object to the data stored in the database.

enter image description here

Advantages of Hibernate:

1) Opensource and Lightweight: Hibernate framework is opensource under the LGPL license and lightweight.

2) Fast performance: The performance of hibernate framework is fast because cache is internally used in hibernate framework. There are two types of cache in hibernate framework first level cache and second level cache. First level cache is enabled bydefault.

3) Database Independent query: HQL (Hibernate Query Language) is the object-oriented version of SQL. It generates the database independent queries. So you don't need to write database specific queries. Before Hibernate, If database is changed for the project, we need to change the SQL query as well that leads to the maintenance problem.

4) Automatic table creation: Hibernate framework provides the facility to create the tables of the database automatically. So there is no need to create tables in the database manually.

5) Simplifies complex join: To fetch data form multiple tables is easy in hibernate framework.

6) Provides query statistics and database status: Hibernate supports Query cache and provide statistics about query and database status.

Information from javatpoint

like image 26
benscabbia Avatar answered Sep 30 '22 18:09

benscabbia