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's real world value Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "hibernate Watch "hibernate New topic
Author

hibernate's real world value

stacy wellington
Greenhorn

Joined: Oct 07, 2005
Posts: 3
what types of applications is it good for?
what types of applications is it bad for?
what are the advantages of using it?
what are the disadvantages of using it?

thus far i have always used jdbc & created my own sql. hibernate has 'coolness' around it, but i don't fall for that. before i invest my time into it, i want to know how it actually adds value to real world projects.

i can think of a simple crud app we have that seems like it would be a good fit. I doubt we could use it in a reporting app.
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
These are really the things that need to be analyzed when scoping a project, it can't be answered simply by asking the question "what is Hibernate good for?".

I've been using/learning Hibernate vigorously for the past 1.5 months and have found it *exceptionally* useful for a wide-array of projects. I too was asking the same questions in the beginning but it all comes down to; what do you need to accomplish w/ your project?

In most cases I've found Hibernate flexible enough to use in most of my projects which are usually business-oriented, data-entry types of web apps at work.

I can see where Hibernate would become cumbersome in a *very* large project...but even then, it has the flexibility to adapt to something larger, I think.

For example, should you need to actually write your SQL - you can. Hibernate doesn't entirely remove the responsibility of knowing anything about your data, quite the contrary - you *need* to know your data...even if you're the programmer in the organization.

The best thing you can do is take it for a test-drive and get an idea of whether you can fit it into your organization or not. It's very easy to learn but it DOES have it's gotchas and tricky curves. For example - my biggest problem was figuring out how to manage the Hibernate Session context (i.e. committing transactions, closing sessions, etc.) - once I got around that, I was rolling along quite nicely.

Why do you doubt you could use it in a reporting app? If you're dealing w/ objects (and you probably are), why wouldn't it be useful? Hibernate has it's place and in some cases it has no place in a project, that is up to you to determine as an analyst.

Hope this helps.

-v
stacy wellington
Greenhorn

Joined: Oct 07, 2005
Posts: 3
i'm looking through appfuse's source code. it has



Is this a common pattern using hibernate to delete an object? does this translate to a 'select' to load the object and then a 'delete' to remove it. 2 sql statements to the db instead of 1 if done the 'old fashioned' way?
Vinnie Jenks
Ranch Hand

Joined: Apr 26, 2004
Posts: 207
The fact that it's using "templates" tells me that the developer has used Spring to manage Hibernate sessions...which can be a good thing (though I haven't tried it myself yet.)

Hibernate allows you to map tables to objects w/ XML so that you can treat your data like an object graph vs. working directly w/ relational data.

Again, the best suggestion would be to walk through the introduction that comes w/ the Hibernate distribution...the basics would take you a couple of hours to understand.
Gerardo Tasistro
Ranch Hand

Joined: Feb 08, 2005
Posts: 362
I see a lot of benefits in Hibernate and few drawbacks. A drawback is size. Obviously if you need a small application Hibernate will just work as bloat. It also requires you to learn it. But once you do a whole set of benefits come alive. The fact that you can do

session.save(myobject);

And let Hibernate handle the SQL creation is a true blessing. For example and as the real world example you ask.

I'm working on migrating our apps (some which are 10+ years old) from Delphi and php to Java. Obviously our merging of formats has lead to a great deal of data structure changes. Lets take two elements: user and client. User is a representation of a human being while client is a company. Now historically records use to be (example, a lot of lines missing):

User {
Name,
LastName,
BirthDate,
Street,
City,
Country,
Zipcode,
HomeTelephone
CellPhone
}

Client {
Name,
Street,
City,
Country,
Zipcode,
Telephone,
Fax
}


Now if I use JDBC and save User and Client I have to create the SQLs to save (also dbase specific, aka dialect). Along the way we decided to create an address class. Keeping telephones separate.

User {
Name,
LastName,
BirthDate,
Address,
HomeTelephone
CellPhone
}

Client {
Name,
Address,
Telephone,
Fax
}

Now this requires a rewrite in the JDBC, and the access of the Address class which now contains
Street,
City,
Country,
Zipcode,

Now with Hibernate all I have to do is modify the hbm (fogive the spanish)>

<class name="Clientes" table="clientes">
<id name="id" column="ID" type="integer">
<generator class="native"/>
</id>

<property name="nombre" column="nombre" type="string" not-null="true" />
<component
name="direccion"
class="DireccionEmpresa">

<property name="direccion1" column="DIRECCION" type="string" not-null="true" />

<property name="ciudad" column="CIUDAD" type="string" not-null="true" />
<property name="codpos" column="CODPOS" type="string" not-null="true" />
<property name="estado" column="ESTADO" type="string" not-null="true" />
</component>
</class>

Declaring the <component> automatically creates an Address class with all data in it upon load and persists it upon save. No say I want to add another address. Say billing or delivery address. I just add another <component> section with a name="shipping address" and add another attribute to the class (obviously).

Now Hibernate also knows what type of class your saving. So I can extend my class into another and just by creating a new hbm file Hibernate will know what to do.

Do I want to add a phone? Well I can create a telephone class that knows how to deal with area codes, country codes etc. Then I add it as another component. Need a cell phone. Works pretty much like a telephone. Well just add a component tag and put the extra fields on the dbase and Hibernate will deal with the rest for you.

No need to be hunting for SQLs. And even if you store SQLs in a resource file you still need to know which one to call given the class your persisting. Am I saving a normal phone class or a cell phone class. A normal user? A client? Hibernate makes all this transparent. Once you get the hang of it your write code withing hours. Really worth the time spent.
Sabarish Sasidharan
Ranch Hand

Joined: Aug 29, 2002
Posts: 73
One rule of thumb could be this...

Is the database schema controlled by the development team or by a different DBA team?
If schema is within your control using Hibernate would be a lot easier because then you can tweak the schema to adjust to Hibernate when you face a problem. But if the schema is not within your control then using Hibernate is still possible but you are going to find one or two roadblocks which would require some investigative time to resolve. Also a lot really depends on Hibernate experience. If you have someone in the team with good expertise then such problems can be remedied. Otherwise it might be difficult.

Hibernate has a steeper learning curve as well.

If you are looking for a simpler OR implementation with more flexibility and lesser learning curve, you can try iBATIS. It is plain simple and quite flexible as well.


Sab<br /> <br />Perfection does not come from belief or faith. Talk does not count for anything. Parrots can do that. Perfection comes through selfless work.<br />Swami Vivekananda
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: hibernate's real world value