To ORM or not to ORM

In the last days I have had a couple of interesting discussions about wether to include an ORM library (such as Hibernate JPA implementation) in an application is a good idea or not.

In this case, as usual, I think there is not a single best choice for every scenario, so I’ll try to list pros (and cons) for each alternative.

Use an ORM layer

I could say this would be my default choice in a new project without any special requirements.

Use plain JDBC

I only recommend this alternative in those few cases where you have extreme performance requirements and/or an experienced DBA in your team.

Use a mixed model

Some years ago I used iBatis (now mybatis as a SQL mapping framework that comes with a great documentation and other niceties such as caching mechanisms, ability to build dynamic queries on the fly, etc.

It was great, but at the end you were forced to maintain a XML file with a bunch of SQL queries and the mappings between your classes and your database structure. With mybatis 3 things seem to have changed: you can stop using an external XML file and use Java annotations instead. They are not standard as far as I know.

I have no experience with it, so I don’t really know wether it is a valid alternative or not.

Extra point: One of my coworkers said “don’t ever let hibernate to create your database schema”. Literally. Do you have any reason to think it is not a good idea?

The post is open to any contribution.