-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 
Author Message
 Post subject: [Newbie question] What makes us use Hibernate?
PostPosted: Thu Apr 18, 2013 5:46 am 
Newbie

Joined: Thu Apr 18, 2013 5:38 am
Posts: 3
Hello,

I am a junior developer, just out from school and on my first dev job.

In my company, I see that the team use an ORM (Hibernate) in the project, but I am not sure why they are using it.

When I ask my team members, I can't get a proper answer, it seems that we are using Hibernate, because, well, everybody uses it.

Is there any particular type of application in which the use of Hibernate (or any ORM) would provide some benefits? And what would be those benefits?

Thanks


Top
 Profile  
 
 Post subject: Re: [Newbie question] What makes us use Hibernate?
PostPosted: Thu Apr 18, 2013 7:55 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
ORM means Object-relational mapping and acts as a bridge between object oriented datastructures (=Java world) and relational datstructures (= relational databases).
The benefits are described on wikipedia http://en.wikipedia.org/wiki/Object-relational_mapping in the section Overview.


Top
 Profile  
 
 Post subject: Re: [Newbie question] What makes us use Hibernate?
PostPosted: Thu Apr 18, 2013 11:14 am 
Newbie

Joined: Thu Apr 18, 2013 5:38 am
Posts: 3
I know well what is the meaning of ORM, and the article on Wikipedia does not describe any benefit.

Quote:
Object-relational mapping and acts as a bridge between object oriented datastructures (=Java world) and relational datstructures


What's the point of it? Why do not write direct SQL statements using JDBC? It's more efficient, and allows to refactor your objects without changing your database or vice versa.


Top
 Profile  
 
 Post subject: Re: [Newbie question] What makes us use Hibernate?
PostPosted: Mon Apr 22, 2013 2:35 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
Why do not write direct SQL statements using JDBC?


Because this means that you will have to write a lot of code doing all this stuff.
For each new added persistent class you again have to write code handling the persistence of that class
(or you write a own generator doing this, which goes already in direction of building an own persistence framework).

Quote:
and allows to refactor your objects without changing your database or vice versa.


This is also feasible with Hibernate.

Quote:
The article on Wikipedia does not describe any benefit.


Sorry, but then you haven't understand the content of this article/section wery well.
Obviously the benefits are not enlisted there using the 'benefit' word,
but it figures out clearly for example, that a ORM does fill\hydrate the persistent java objects for you with correct data,
when reading a records from database, without that you have to write specific code for that.

Try to build an application where the persistence includes classes using extensions (class-hierarchies) and relations (aggregations and associations). Try to do it with Hiberante and the same with plain JDBC, so you will understand the difference.
When you navigate for example a relation in Hibernate, then Hibernate does all needed stuff for you (check whether the associated item(s) are already cached, execute the proper sql against the db to get the associated items etc.), with plain JDBC you have to write a lot of code there.


Top
 Profile  
 
 Post subject: Re: [Newbie question] What makes us use Hibernate?
PostPosted: Wed Apr 24, 2013 12:31 am 
Newbie

Joined: Thu Apr 18, 2013 5:38 am
Posts: 3
So you think that having the same model for data and for application business logic is a good idea?

It is a big smell.
Another big smell is that you need to have getters and setters in your business objects, so that leads to awful code.

The fact that you need to write more code is not true, you can just use some lightweight framework (using Spring for jdbcTemplate for example).
So instead of modifying so .xml mapping file or some annotation, you will just change a bit your SQL statement.

What's the big deal?


Top
 Profile  
 
 Post subject: Re: [Newbie question] What makes us use Hibernate?
PostPosted: Wed Apr 24, 2013 2:27 am 
Regular
Regular

Joined: Wed Apr 10, 2013 1:02 am
Posts: 50
Hey man Hibernate is a framework unlike any framework it is a result of evolution.
As you are just out of school as u mentioned you won't be able to understand it's usage unless you build one around
JDBC and see the tradeoff

_________________
Regards
Akash Miital
http://akash.thegrassroots.co.in/hibernate/


Top
 Profile  
 
 Post subject: Re: [Newbie question] What makes us use Hibernate?
PostPosted: Wed Apr 24, 2013 8:48 am 
Expert
Expert

Joined: Tue Jun 16, 2009 3:36 am
Posts: 990
Quote:
So you think that having the same model for data and for application business logic is a good idea?


No, and I never stated that.
Hiberante does just the mapping, it does not include any application business logic.
I think you are confounding here some concepts.

Quote:
you need to have getters and setters in your business objects, so that leads to awful code.


This is just your personal opinion. For most people (see for example EJB) using getters and setters means not have awful code.

Quote:
The fact that you need to write more code is not true, you can just use some lightweight framework (using Spring for jdbcTemplate for example).


I would say it depends primarily on the complexity of your business application.
And what about things like optimistic locking, write behind mechnism, dirty-entity-tracking, second level caches, auditing, statictics etc.. these are all things which Hibernate has onboard, I thing jdbcTemplate dont have all these features.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.