Java Hibernate 的轻量级替代品?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/296587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 12:43:10  来源:igfitidea点击:

Light weight alternative to Hibernate?

javadatabasehibernatesqlite

提问by Jared

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 程序,我希望将数据存储在轻量级数据库中,例如 Derby 或 Sqlite。我想在我的程序中使用数据抽象层。Hibernate 似乎需要很多配置,对于我需要的东西来说太过分了。什么是 Hibernate 的轻量级替代品?

采纳答案by Vladimir Dyuzhev

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 andpower point of view.

如果您使用注释,Hibernate 需要接近零配置。它甚至可以自动发现类路径中的映射 bean!从简单性强大的角度来看,我认为没有任何替代方案。

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

它还可以将自己公开为 JPA,这(恕我直言)更简单。

回答by kgiannakakis

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

它仍然需要 XML 配置,但请查看MyBatis(以前称为 iBatis)

回答by Benno Richters

Cayennehas 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.

卡宴对我很有帮助。相对容易理解和启动并运行。我发现逆向工程部分特别迷人。可以使用 GUI 进行配置。

回答by Stephan Eggermont

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?

您可能想看看 prevayler(在 sourceforge 上)。一种更轻量级的持久性方法。或者您是否正在考虑针对数据库进行报告?

回答by Christopher Graziano

Apache Commons DBUtilstakes 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.

Apache Commons DBUtils消除了 JDBC 编程中的大量重复性工作。它需要很少的配置并且很容易学习。它不是一个 ORM 框架(就像这里提到的 Hibernate 和其他框架一样),但它确实自动将 SELECT 列映射到 Java 成员字段以及其他重复的 JDBC 编程任务。它当然是轻量级的。

回答by Rob

You can have a look at Ebean ORM. - No sessions - lazy loading just works - Simpler API to use and learn.

你可以看看Ebean ORM。- 没有会话 - 延迟加载才有效 - 使用和学习更简单的 API。

回答by Gray

My ORMLitelibrary 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..

我的ORMLite库就是这样一种选择。它支持 MySQL、Postgres、Microsoft SQL Server、H2、Derby、HSQLDB 和 Sqlite,并且可以很容易地扩展到其他人。它使用注解来配置类、良好的 Spring 支持、灵活的查询构建器等。

回答by Lukas Eder

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

jOOQ附带了一个直接在 Java 中模拟 SQL 的流畅 DSL,作为其主要目标的副作用,这些目标是:

  • 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.
  • 源代码生成
  • 完全支持标准 SQL,包括 SQL 语言功能,例如 UNION、嵌套 SELECT、所有类型的 JOIN、别名(例如用于自连接)等
  • 广泛支持非标准 SQL,包括 UDT、存储过程、供应商特定函数等。

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

在本文中了解 jOOQ:http://java.dzone.com/announcements/simple-and-intuitive-approach ,或直接访问网站:http: //www.jooq.org

(Disclaimer, I work for the company behind jOOQ)

(免责声明,我为 jOOQ 背后的公司工作)

回答by Somatik

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

我可以提出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.

Apache Empire-db 是一个开源关系数据持久化组件,它允许独立于数据库供应商的动态查询定义以及安全和简单的数据检索和更新。与大多数其他解决方案(例如 Hibernate、TopLink、iBATIS 或 JPA 实现)相比,Empire-db 采用了截然不同的方法,特别关注编译时安全、减少冗余和提高开发人员生产力。

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);;

回答by Behrang Saeedzadeh

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

如果使用关系数据库不是强制性的,请尝试 db4o。