It's a pretty open ended question. I'll be starting out a new project and am looking at different ORMs to integrate with database access.
Do you have any favorites? Are there any you would advise staying clear of?
It's a pretty open ended question. I'll be starting out a new project and am looking at different ORMs to integrate with database access.
Do you have any favorites? Are there any you would advise staying clear of?
Hibernate, because it's basically the defacto standard in Java and was one of the driving forces in the creation of the JPA. It's got excellent support in Spring, and almost every Java framework supports it. Finally, GORM is a really cool wrapper around it doing dynamic finders and so on using Groovy.
It's even been ported to .NET (NHibernate) so you can use it there too.
SimpleORM, because it is straight-forward and no-magic. It defines all meta data structures in Java code and is very flexible.
SimpleORM provides similar functionality to Hibernate by mapping data in a relational database to Java objects in memory. Queries can be specified in terms of Java objects, object identity is aligned with database keys, relationships between objects are maintained and modified objects are automatically flushed to the database with optimistic locks.
But unlike Hibernate, SimpleORM uses a very simple object structure and architecture that avoids the need for complex parsing, byte code processing etc. SimpleORM is small and transparent, packaged in two jars of just 79K and 52K in size, with only one small and optional dependency (Slf4j). (Hibernate is over 2400K plus about 2000K of dependent Jars.) This makes SimpleORM easy to understand and so greatly reduces technical risk.
Pluses for Hibernate are that it is a de facto standard and is well documented. Negatives are that it has some nasty little quirks (including a fondness for failing silently) and the JAR dependencies are a mess. Also, the development team has a reputation for being somewhat tetchy (which is only an issue if you might need their help).
If you're specifically looking at JPA implementations, you might also consider Open JPA, which is much saner, though not nearly as widely used. There is also Toplink, but I have no experience with that (other than a co-worker telling me that his project had stopped using it and switched to Hibernate because Toplink was "****ing ****").
Eclipse Link, for many reasons, but notably I feel like it has less bloat than other main stream solutions (at least less in-your-face bloat).
Oh and Eclipse Link has been chosen to be the reference implementation for JPA 2.0
I have stopped using ORMs.
The reason is not any great flaw in the concept. Hibernate works well. Instead, I have found that queries have low overhead and I can fit lots of complex logic into large SQL queries, and shift a lot of my processing into the database.
So consider just using the JDBC package.
None, because having an ORM takes too much control away with small benefits. The time savings gained are easily blown away when you have to debug abnormalities resulting from the use of the ORM. Furthermore, ORMs discourage developers from learning SQL and how relational databases work and using this for their benefit.
I had a really good experience with Avaje Ebean when I was writing a medium sized JavaSE application.
It uses standard JPA annotations to define entities, but exposes a much simpler API (No EntityManager or any of that attached/detached entities crap). It also lets you easily use SQL queries or event plain JDBC calls when necessary.
It also has a very nice fluid and type-safe API for queries. You can write things like:
List<Person> boys = Ebean.find(Person.class)
.where()
.eq("gender", "M")
.le("age", 18)
.orderBy("firstName")
.findList();
Hibernate, because it:
A few points on why (and when) to use ORM:
I would recommend using iBatis.It is a thin layer on top of JDBC, it is very easy to map objects to tables and still use plain SQL, everything is under your control.
I've been pondering the same question myself and have decided to go with Apache Cayenne.