About choosing object relational mapping framework in Java

633 Views Asked by At

I am currently creating a some DAO in Java. But the application is not very large, so I am not consider to use hibernate or JPA. What light-weight framework can I use?? Thank :D

3

There are 3 best solutions below

4
On

Neither Hibernate nor JPA would be what I would call "lightweight".

I'd recommend Spring JDBC template or iBatis. Or just straight JDBC. How hard can it be?

If you don't have a solid object model, no ORM solution will help you. The "O" stands for "object".

If you know SQL well and want to think in terms of relations, I'd say that ORM is a bad choice.

4
On

Take a look at ormLite. It's intended to be a lightweight ORM tool, but if I'm completely honest, I'd take duffymo's advice an just go Spring JDBC.

0
On

The lightest solution - in terms of setup - would be Eclipselink (which is a JPA implementation). Using Hibernate would yield identical code (because it is a JPA implementation too), but would require more dependencies.

To use Eclipselink you just need three jars in your classpath and a very short configuration file (META-INF/persistence.xml). The simplest way to see which jars exactly would be to use Netbeans and add them using libraries->add->eclipselink (jpa 2.1).

No matter which solution you choose you also need a relevant JDBC driver.

If you are a beginner, a JPA library (like Eclipselink or Hibernate JPA) is a good choice because:

  • your IDE will probably have some tooling to help you with persistence.xml and mapping;
  • it is a very popular standard and programmers generally agree that it's good;
  • it let's you do simple things very easily; bootstrapping is one line of code, configuring a simple class can be done in just two annotations;
  • it let's you grow: when you want to use Java EE stack one day, it will be good to know JPA.