aspose file tools*
The moose likes Object Relational Mapping and the fly likes Doubt in a Hibernate feature Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Doubt in a Hibernate feature" Watch "Doubt in a Hibernate feature" New topic
Author

Doubt in a Hibernate feature

ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Dear all,
I've just now started to learn & use Hibernate.
1)While going through the Hibernate Tutorials I come across a feature of Hibernate named "Caching Solutions".

Caching solutions, transactions and other features Hibernate provides are not so easy to implement. It is actually non sense to develop something which allready exist.


What does "Caching solutions" means .Where & why is it used in business applications. If you could refer simple business scenario where "Caching solutions" are implemented it could be very helpful to me.
How is it implemented through Hibernate?

2)I read that using of Hibernate results in a better system architecture

When you include all functionality of your application and the access to the database within your dialogs, you will have some severe disadvantages.

It is really difficult to reuse code. You will repeat code at many places. If you change anything it is quite hard to find out all places where you have to add changes.

When you separate your dialogs from your logic and the logic from the persistence mechanism you can more easily apply changes to one part without influencing the other parts.

What is this & what do they mean by dialogs?

Those are my doubts & I would appreciate your help in this regard.
Cheers
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


What does "Caching solutions" means .Where & why is it used in business applications. If you could refer simple business scenario where "Caching solutions" are implemented it could be very helpful to me.

A cache caches data somewhere outside the database. This could be in memory, or in another persistance mechanism.

There are many existing products that provide caches (fort example EHCache,
JCS, JBoss Cache etc.) so this is why Hibernate does not provide one itself. It does provide an integration mechanism to use these exiting solutions.

There is only one business reason to use a cache: performance. Some data changes very little, is used in many places in an application and is shared between many people. This results in an overhead, that could be significant, to always have to go to the database to get it. Better to go to the cache for this.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Thanks paul for your reply.
It was a good learning experience for me from experts .
Also I still didn't get clear picture of my second doubt.
" How Hibernate results in a better system architecture"
Any light on this?
Regards
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
Any one listening?
Reehan Lalkhanwar
Ranch Hand

Joined: Jun 16, 2007
Posts: 106
With the DB separate and with no requirement to write any query for any of the DB transaction, its really convenience with Hibernate that would strike a programmer.
Also the objects/classes being modeled based on the underlying DB it gives a real-world picture to the programmer and makes life easier.
I think the "dialogs" mentioned are the interactions with the user and the program.


Thank you,
Reehan
ramya narayanan
Ranch Hand

Joined: Oct 06, 2008
Posts: 338
No, they were saying that we can reuse code in Hibernate which makes Hibernate resulting in a better system architecture

When you include all functionality of your application and the access to the database within your dialogs, you will have some severe disadvantages.

It is really difficult to reuse code. You will repeat code at many places. If you change anything it is quite hard to find out all places where you have to add changes.

When you separate your dialogs from your logic and the logic from the persistence mechanism you can more easily apply changes to one part without influencing the other parts.


Through some light on this?
Ridhav Mahajan
Greenhorn

Joined: Oct 23, 2008
Posts: 11
""When you include all functionality of your application and the access to the database within your dialogs, you will have some severe disadvantages.""

This talks of a scenario when you are calculating or applying some business logic in a function and then saving that value in oracle database in same function, lets say.
Now what happens if you have to change the database at back end or upgrade it. Now your code will be tightly coupled with the databse calls and it will be difficult and time consuming to change all this and Consider a very big business application, here this change can itelf become a big overhead.
hence there comes advantage of layered architecture. where functionality is separated from databse calls. But hibernate gives advantages one step ahead of this.
Now lets take the same example stated above. When you are using hibernate, for CRUD(create,read,update,delete) you are just calling plain java methods , without writing any sql, and connection settings are also defined in xml files.
Hence in this case if you are changing back end databse or some other changes, your code is very loosely coupled, and all you require is to change some property or xml files adn here you go.


Ridhav
Ridhav Mahajan
Greenhorn

Joined: Oct 23, 2008
Posts: 11
"Caching solutions, transactions and other features Hibernate provides are not so easy to implement. It is actually non sense to develop something which allready exist."

I guess this lines itself says everything "It is actually non sense to develop something which allready exist.". there is no use of re inventing the wheel. Hibernate provides a good caching mechanism.
It actually caches your object in the session and when ever you change something in your object, that objects become dirty and gets changed in session , not in database directly.
i.e when you actually save or persist something, hibernate persists it in its session and then next time hibernate is going to database to get something, it will then check whether some dirty objects exists in session and then it wil save them in database.

That is one of the important reason a method "flush" is often used in hibernate where you want the hibernate to hit database immidiately and persist there rather than persisting something in session.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

"Ridhav", please check your private messages.
 
 
subject: Doubt in a Hibernate feature