db-torque-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bill Schneider <bschnei...@vecna.com>
Subject Re: Hibernate vs. Torque
Date Wed, 30 Jul 2003 18:13:52 GMT
I've used both and they are both good for different things.  It's easier 
to get up and running with Torque, because it's simpler and doesn't try 
to do as much.  On the other hand, with more complex projects, Hibernate 
may be better.

Torque is more database-centric.  You use the Torque-generated objects 
in a database-like idiom.  You can touch foreign key IDs directly. You 
need explicit mapping objects for many-to-many relationships, as 
objects/peers and tables always match 1-to-1. 

Hibernate is more object-centric.  You can't touch foreign keys 
directly, and you don't need map objects for many-to-many relations.  
Hibernate can handle the concept of ordered collections like Lists in 
the database, while in Torque you would have to maintain the sort key 
yourself.  It does cascaded updates/deletes natively, while Torque 
relies on the database's native support. 

These extra features can either be a blessing or a curse.  There's a 
much steeper learning curve for getting it all straight, and there are 
lot more options for configuration.  On the other hand, once it's up and 
running, it is very powerful.  Also, you may sacrifice some performance 
for the stronger abstraction layer, especially with many-to-many 
relations.  For example, in Torque you can just say "add mapping from  
an A to a B" as the A-B mapping is itself an entity.  But in Hibernate 
you have to load all the As, load all the related Bs (at least the IDs 
for them), then add the B to the collection. 

things that seem to be purely advantages to Hibernate (same goes for OJB 
and Castor):
- use of POJO (plain old java objects) for data model means data model 
is not coupled to persistence layer, and can be used in different 
contexts (e.g., return value from SOAP service)
- bind variables and prepared statement used by default
- object query language
- persisting collections of "primitive" non-entities (e.g., a List of 
- Lazy-loading tends to work better

On the other hand, if you want to make a quick prototype, Torque is 
easier to get going with.

I've also looked at Castor and OJB, and it looked like Hibernate was 
more active and better supported.  Hibernate doesn't attempt to solve 
the JDO problem in general, but it is specific to relational persistence 
and does that one job pretty well. 

-- Bill

Brian McCallister wrote:

> I would highly recommend checking out OJB if you are looking to try a 
> new O-R tool =)
> OJB and Hibernate both focus on persisting arbitrary Java classes, 
> compared to Torque which uses code generation to create the persistent 
> classes.
> -Brian

To unsubscribe, e-mail: torque-user-unsubscribe@db.apache.org
For additional commands, e-mail: torque-user-help@db.apache.org

View raw message