Light weight alternative to Hibernate? [closed]

2020-01-27 09:11发布

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?

14条回答
地球回转人心会变
3楼-- · 2020-01-27 09:57

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);;
查看更多
爷的心禁止访问
4楼-- · 2020-01-27 09:57

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.

查看更多
萌系小妹纸
5楼-- · 2020-01-27 10:01

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.

查看更多
相关推荐>>
6楼-- · 2020-01-27 10:02

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)

查看更多
再贱就再见
7楼-- · 2020-01-27 10:04

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

查看更多
登录 后发表回答