File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Object Relational Mapping and the fly likes Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Hibernate" Watch "Hibernate" New topic
Author

Hibernate

Ankur Saxena
Greenhorn

Joined: Dec 28, 2005
Posts: 11
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

Joined: Oct 15, 2005
Posts: 163
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

Joined: Feb 08, 2005
Posts: 362
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

Joined: Dec 28, 2005
Posts: 11
Thks all for your replies.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Hibernate
 
Similar Threads
Domain object model
Struts + Hiberante ?
question about persistence layer and business logic layer
Table Oriented Programming
Usage of 'programming to an interface'