Light weight alternative to Hibernate?

JavaDatabaseHibernateSqlite

Java Problem Overview


I have a single user java program that I would like to have store data in a light weight database such as Derby or Sqlite. I would like to use a data abstraction layer in my program. Hibernate appears to require a lot of configuration and is overkill for what I need. What are light weight alternatives to Hibernate?

Java Solutions


Solution 1 - Java

Hibernate requires next to zero configuration if you use annotations. It even can auto-discover mapped beans in the classpath! I don't see any alternative to it from both simplicity and power point of view.

It can also expose itself as JPA, which is (IMHO) even simpler.

Solution 2 - Java

My ORMLite library is one such alternative. It supports MySQL, Postgres, Microsoft SQL Server, H2, Derby, HSQLDB, and Sqlite, and can be easily extended to others. It uses annotations to configure classes, good Spring support, flexible query builder, etc..

Solution 3 - Java

It still requires XML configuration, but have a look at MyBatis (formerly iBatis).

Solution 4 - Java

jOOQ ships with a fluent DSL simulating SQL directly in Java as a side-effect for its main goals which are:

  • Source code generation
  • Full support for standard SQL including SQL language features such as UNIONs, nested SELECTs, all types of JOINs, aliasing (e.g. for self-joins), etc
  • Wide support for non-standard SQL including UDT's, stored procedures, vendor-specific functions, etc.

Read about jOOQ in this article: http://java.dzone.com/announcements/simple-and-intuitive-approach, or visit the website directly: http://www.jooq.org

(Disclaimer, I work for the company behind jOOQ)

Solution 5 - Java

Apache Commons DBUtils takes much of the repetitive gruntwork out of JDBC programming. It requires little configuration and is easy to learn. It is not an ORM framework (in the way that Hibernate and other frameworks mentioned here are) but it does automate mapping of SELECT columns to Java member fields as well as other repetitive JDBC programming tasks. It's certainly lightweight.

Solution 6 - Java

You can have a look at Ebean ORM.

  • No sessions

  • lazy loading just works

  • Simpler API to use and learn.

Solution 7 - Java

Cayenne has served me well. Relatively easy to understand and to get it up and running. I find the reverse engineering part particularly charming. Configuration can be done with a GUI.

Solution 8 - Java

I can propose apache empire-db. http://incubator.apache.org/empire-db/

Apache Empire-db is an Open Source relational data persistence component which allows database vendor independent dynamic query definition as well as safe and simple data retrieval and updating. Compared to most other solutions like e.g. Hibernate, TopLink, iBATIS or JPA implementations, Empire-db takes a considerably different approach, with a special focus on compile-time safety, reduced redundancies and improved developer productivity.

An example:

// Define the query
DBCommand cmd = db.createCommand();
DBColumnExpr EMPLOYEE_FULLNAME= db.EMPLOYEES.LASTNAME.append(", ")
                        .append(db.EMPLOYEES.FIRSTNAME).as("FULL_NAME");
// Select required columns
cmd.select(db.EMPLOYEES.EMPLOYEE_ID, EMPLOYEE_FULLNAME);
cmd.select(db.EMPLOYEES.GENDER, db.EMPLOYEES.PHONE_NUMBER);
cmd.select(db.DEPARTMENTS.NAME.as("DEPARTMENT"));
cmd.select(db.DEPARTMENTS.BUSINESS_UNIT);
// Set Joins
cmd.join(db.EMPLOYEES.DEPARTMENT_ID, db.DEPARTMENTS.DEPARTMENT_ID);
// Set contraints and order
cmd.where(EMP.LASTNAME.length().isGreaterThan(0));
cmd.orderBy(EMP.LASTNAME);;

Solution 9 - Java

Solution 10 - Java

I might be a bit late to the party, but I released ActiveJDBC in 2010, which is an ORM implementation of ActiveRecord pattern, is more than 10 times lighter than Hibernate in dependencies, at least twice as fast at run time, and requires zero configuration or annotations.

Solution 11 - Java

You might want to take a look at prevayler (on sourceforge). A somewhat more lightweight approach to persistence. Or were you thinking about doing reporting against the DB?

Solution 12 - Java

If using a relational database is not mandatory, give db4o a try.

Solution 13 - Java

I created sormula as an alternative to heavyweight ORM's. It is CRUD-ready, POJO-friendly, simple to use, configure, and understand. Zero-configuration use is possible. www.sormula.org

Solution 14 - Java

Kiteframework is also very light orm framework. It provides almost all db operation with minimal configurations.

http://deipakgarg.github.com/Kite-ORM/

Disclosure: I am the author of this project

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJaredView Question on Stackoverflow
Solution 1 - JavaVladimir DyuzhevView Answer on Stackoverflow
Solution 2 - JavaGrayView Answer on Stackoverflow
Solution 3 - JavakgiannakakisView Answer on Stackoverflow
Solution 4 - JavaLukas EderView Answer on Stackoverflow
Solution 5 - JavaChristopher GrazianoView Answer on Stackoverflow
Solution 6 - JavaRobView Answer on Stackoverflow
Solution 7 - JavaBenno RichtersView Answer on Stackoverflow
Solution 8 - JavaSomatikView Answer on Stackoverflow
Solution 9 - Javaahmet alp balkanView Answer on Stackoverflow
Solution 10 - JavaipolevoyView Answer on Stackoverflow
Solution 11 - JavaStephan EggermontView Answer on Stackoverflow
Solution 12 - JavaBehrangView Answer on Stackoverflow
Solution 13 - JavaJeff MillerView Answer on Stackoverflow
Solution 14 - JavaDeipakGargView Answer on Stackoverflow