Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate

 
Ankur Saxena
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I am new in the Hibernate world, till now I am working on business logic with JDBC and Java Stored Procedures. I wanna know if I need 10 values from 10 different tables to use these values in my business logic then di I have to create 10 objects of beans 10 table mappings in Hibernate ,but through JDBC I can create a view and do the same then tell me how Hibernate reducing the complexity in this case.
 
Michael Duffy
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankur Saxena:
Hi all,

I am new in the Hibernate world, till now I am working on business logic with JDBC and Java Stored Procedures. I wanna know if I need 10 values from 10 different tables to use these values in my business logic then di I have to create 10 objects of beans 10 table mappings in Hibernate ,but through JDBC I can create a view and do the same then tell me how Hibernate reducing the complexity in this case.


If those 10 values should appear in 10 tables, you should be able to JOIN them together. If you can write enough SQL to present them as a single view, you should be able to manage it in Hibernate, too.

The larger question is: where is it appropriate to do the JOIN?

One benefit of creating that view is information hiding. Clients of your database can treat the view as an interface. You can normalize/denormalize the tables behind it to your heart's content, as long as you don't change the contract with clients.

Complexity is what it is. I don't think Hibernate will eliminate it if it's already present in your data model. Hibernate just provides a way to map from objects to the relational model and back. The idea is that the object and relational models should be independent. What's best for one isn't always optimal for the other. Hibernate allows them to vary independently.

%
 
Gerardo Tasistro
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ankur Saxena:
di I have to create 10 objects of beans 10 table mappings in Hibernate ,but through JDBC I can create a view and do the same then tell me how Hibernate reducing the complexity in this case.


Yes you have to create the 10 mappings so Hibernate knows how to work with the tables. I use a tool called MyEclipse (www.myeclipseide.com) at about 30 US dollars it is good bang for the buck. Among its many utilities it has a dbase interface that creates the hbm and java files from the dbase structure. So creating 10 mappings is a minute's worth of work.

The benefit and reduced complexity then lays on the reduced code and ease of upgrades/modifications. You can easily modify code by just changing the hbm file. Secondly you can have the HQLs stored in the hbm file as strings and then create a query by name. So all your SQL code is centralized in the hbm file. Finally the dbase independence in regards to the actual generated SQL code is great. Just change the dialect to change the dbase you use. Don't you just love those projects in sourceforge that say "only with DB2" or "only with MySQL".
 
Ankur Saxena
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thks all for your replies.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic