aspose file tools*
The moose likes Object Relational Mapping and the fly likes Disadvantages of Hibernate Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Disadvantages of Hibernate" Watch "Disadvantages of Hibernate" New topic
Author

Disadvantages of Hibernate

Gayatri Ganesh
Ranch Hand

Joined: Dec 23, 2003
Posts: 143
Hi Everyone,

I have been reading about Hibernate for a few days from now.
I have read about its adavntages, what it is capable of doing, etc.
Today someone at work asked me about its disadvantages. I did not know what the answer was.
Does anyone have an answer to this question ?

Thanks,
-Gayatri
Sathya Srinivasan
Ranch Hand

Joined: Jan 29, 2002
Posts: 379
Some disadvantages (or inconveniences) I have encountered so far are

1. Not that flexible when it comes to mapping composite-ids (although you can do a lot). While this is not a fault of Hibernate as composite-ids are typically used in legacy systems, it can be a pain when attempting to map legacy tables.

2. Everything is an object. If you need only a portion of data (say, for a search), you would still have to retrieve the object. However, this is true for any ORM strategy.

3. In some cases, you will encounter the (n+1) select problem. That is, Hibernate will execute (n+1) queries for going through a list of records of size n. There are some mechanisms suggested by Hibernate that can be used to mitigate this risk.

4. Till Hibernate 3, you cannot map multiple tables to a single class. This has been fixed in Hibernate 3 using the join tag.

In general, Hibernate is a very powerful and flexible tool. After using it for 6 months, I see myself thinking about using Hibernate whenever I need to talk to databases (except for extremely simple scenarios).


Cheers, Sathya Srinivasan - SCJP 1.2, SCWCD 1.2, SCMAD 1.0
Co-Author of Whizlabs SCMAD Certification Exam Simulator and SCMAD Exam Guide Book
Salomon Zalzman
Greenhorn

Joined: Mar 03, 2005
Posts: 9
Also, It does not come out of the box with visual tools for editing meta data or relational mapping. Some third party tools provide visualization for specific portions of Hibernate development but no one tool has all the capabilities so several tools must be used.

As far as pricing, the leading JDO vendors offer very attractive pricing models as compared to Hibernate as there is only a marginal cost for development licenses and no runtime charge. It is worth considering a JDO solution in your planning.

Salomon Zalzman
Versant Corporation
www.versant.com
Chris Johnston
Ranch Hand

Joined: Dec 13, 2004
Posts: 85
Originally posted by Salomon Zalzman:
As far as pricing, the leading JDO vendors offer very attractive pricing models as compared to Hibernate as there is only a marginal cost for development licenses and no runtime charge. It is worth considering a JDO solution in your planning.


Isn't Hibernate free? Thus making it the cheaper and more attractive of the two options?


www.fuzzylizard.com
David Harkness
Ranch Hand

Joined: Aug 07, 2003
Posts: 1646
Some people believe the saying "You get what you pay for." Of course, many people also believe that commercial software means good support.
anthony patricio
Greenhorn

Joined: Mar 04, 2005
Posts: 1
Sathya,
1. Not that flexible when it comes to mapping composite-ids (although you can do a lot). While this is not a fault of Hibernate as composite-ids are typically used in legacy systems, it can be a pain when attempting to map legacy tables.

partially wrong, using composite-id seems much harder but it isn't and of course it is possible to map composite-ids

2. Everything is an object. If you need only a portion of data (say, for a search), you would still have to retrieve the object. However, this is true for any ORM strategy.

wrong, HQL example: select person.name, person.height from com.Person, it doesn't return an instance of Person....

3. In some cases, you will encounter the (n+1) select problem. That is, Hibernate will execute (n+1) queries for going through a list of records of size n. There are some mechanisms suggested by Hibernate that can be used to mitigate this risk.

again, with fetch keyword and batch-size you cannot have a n+1 problem, a (n/batch-size)+1 problem... maybe

Salomon,
hibernate tools are in progress, i always think it's better to focus on the core features than in the visual artifacts...
My POV is that mapping editor + schemaexport are sufficient to have a great productivity

last, hibernate is free but if you need professionnal support (which is normal) you can get strong expert support from JBoss.

Hope this help,
Anthony
Hibernate
[ March 04, 2005: Message edited by: anthony patricio ]
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336


quote:
--------------------------------------------------------------------------------
2. Everything is an object. If you need only a portion of data (say, for a search), you would still have to retrieve the object. However, this is true for any ORM strategy.
--------------------------------------------------------------------------------


wrong, HQL example: select person.name, person.height from com.Person, it doesn't return an instance of Person....

What does it return then, if not an Object?


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Lasse Koskela
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
For example,

would return an Object[] of two elements of type java.lang.String.


Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Axel Janssen
Ranch Hand

Joined: Jan 08, 2001
Posts: 2164
Here is an interesting article about ibatis sqlmaps as a more low level alternative.
http://www.onjava.com/pub/a/onjava/2005/02/02/sqlmaps.html
I interpret low level as less confusing at first, probably more maintainance-work in the long run and generally more handcoding.

If you don't know the database very well, hibernates transparency might make problems difficult to spot. I have shot in my shoe at weekend, while trying to create tables in HypersoniqSQL-DB with hbm??? tool (the tool to generate RDBMS tables from hbm.xml mapping files).
I think the source of the problem was that I've used long datatype in an identy column. Only Integer appears to be allowed. Haven't found no log-messages which explained that.
I like hibernate a lot and hibernate in action was a sometimes challenging but very good read last year. Nevertheless I'ld recommend to not see hibernate as the "hammer" for all "rdbms-issues" in java.
Better to diversify knowledge about rdbms-integration issue like EJB-Entity beans, ibatis sqlmaps, self-written more-or-less-ad-hoc-frameworks and more conceptual stuff which is not bound to a special framework (like optimistic/pessimistic locking, DAO-Pattern, know-features-of-DB-you-are-using well)

Axel
kundan varma
Ranch Hand

Joined: Mar 08, 2004
Posts: 322
Hi chris
Even JPOX is free
Thanks
kundan


SCJP1.4,SCBCD,SCEA,CNA
Failures are practice shoots for success.
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
my 2 cents:

2. Everything is an object. If you need only a portion of data (say, for a search), you would still have to retrieve the object. However, this is true for any ORM strategy.


You can use projection to retrieve only part of a mapped entity. Assume Person has a number of properties (Address, Phonenumber, ...,name and age) :

NOTE: Does not work with collections (at least in Hibernate 2, i do not know if Hibernate 3 can handle them).


3. In some cases, you will encounter the (n+1) select problem. That is, Hibernate will execute (n+1) queries for going through a list of records of size n. There are some mechanisms suggested by Hibernate that can be used to mitigate this risk.


You can use [url=http://"http://www.hibernate.org/hib_docs/api/net/sf/hibernate/Criteria.html"]setFetchMode()[/url] , eager fetching in HQL, outer join settings to control the way collections are loaded.



pascal
Brice Laurencin
Greenhorn

Joined: Feb 23, 2005
Posts: 8
Originally posted by pascal betz:
my 2 cents:

NOTE: Does not work with collections (at least in Hibernate 2, i do not know if Hibernate 3 can handle them).



You can use [url=http://"http://www.hibernate.org/hib_docs/api/net/sf/hibernate/Criteria.html"]setFetchMode()[/url] , eager fetching in HQL, outer join settings to control the way collections are loaded.



pascal


I have a few little questions about the "select new" : How does it work ?!
does the object we want to instanciate have to be declared in an hbm.xml file ?
is it possible to do a "select distinct new ... " ?
Help... I don't find any info, even in Hibernate in Action...

Brice.


"If idiots couldn�t get jobs for which they are unqualified, your workplace would be empty right now." - Scott Adams
Mark Lundquist
Greenhorn

Joined: Mar 30, 2005
Posts: 5
I have a few little questions about the "select new" : How does it work ?!
does the object we want to instanciate have to be declared in an hbm.xml file ?
is it possible to do a "select distinct new ... " ?
Help... I don't find any info, even in Hibernate in Action...

Brice.


Hi Brice,

Look under �7.4.1, "Projection" in HiA (p. 271 in my copy :-).

The result class does not have to be a mapped class ��I think the only requirement is that it have a constructor with a matching profile (or signature or whatever you want to call it).

I do not know if "select distinct new..." is possible. I would expect that it is.

HTH,
�ml�
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Disadvantages of Hibernate
 
Similar Threads
EJBHandle
Advantanges of JNI
disadvantages of HIbernate
Hibernate - Query language independency
Advantages of EJB 3/JPA over spring/hibernate