• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

iBatis and Hibernate in same book?

 
Chris Thompson
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris, it seems like these two projects come head-to-head a lot. I've noticed from other threads that you've tried to incorporate conversation on both in your book. Thoughts on the key criteria when one makes a lot more sense than the other based on your experiences?
 
Chris Richardson
author
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,

In general like using an ORM framework because its higher-level. There is general less code to write and maintain. It gives you portability across databases, which is useful even if you only have one DB in production because you can easily switch between with HSQLDB for testing and your production database. The performance optimizations such as eager and lazy loading and caching are extremely valuable.

Having said that, there are situations where using an ORM generally does not make sense. For example:
* Your application accesses a weird and wonderful(denormalized) legacy schema that can't be mapped to a nice object model
* Your DBA insists you storing all of your SQL statements in a file for their inspection and tuning
* Your DBA requires all database accesses to go through stored procedures.
* You need to perform certain kinds of bulk operations such as batch operations that manipulate a large number of rows
* You need to use DB-specific SQL features

Keep in mind though that some ORM frameworks such as Hibernate have features to support the last two points and have some support for stored procedures.

If you can't use an ORM framework I would highly recommend using iBATIS. Over the years I taken the following path. Pure JDBC (never again) -> Homegrown SQL framework -> Spring JDBC -> iBATIS. I quite liked Spring JDBC but then I discovered iBATIS and was very impressed with its power.

So in summary: use ORM if it makes sense. Use iBATIS when you must.

Chris
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your application accesses a weird and wonderful(denormalized) legacy schema that can't be mapped to a nice object model


Chris,

Could you give an example.
 
Chris Richardson
author
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pradip,

A common problem is a denormalized schema. For example, the first four elements of a 1-N relationship are stored in the parent table instead of the child table in order to eliminate a join.

create table orders (
...
order_line_1_quantity,
order_line_2_quantity,
order_line_3_quantity,
order_line_4_quantity,
order_line_1_product_id,
order_line_2_product_id,
order_line_3_product_id,
order_line_4_product_id,
)

create table order_lines (

)

You would have to mirror the denormalization in the object model (as is being discussed here http://www.coderanch.com/t/216016/ORM/java/ORM-normalization), which can be unpleasant.

I'm sure others who work for large corporations have some other examples

Chris
[ January 25, 2006: Message edited by: Chris Richardson ]
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic