用于小型项目的简单 Java ORM

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5745064/
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-10-30 12:33:35  来源:igfitidea点击:

Easy Java ORM for small projects

javaormpersistence

提问by Chris

I'm currently searching for a really easy way to get simple Java Objects persistent in Databases and/or XML and/or other types of data stores.

我目前正在寻找一种非常简单的方法来将简单的 Java 对象持久化到数据库和/或 XML 和/或其他类型的数据存储中。

For big projects in the company i would use hibernate, ibatis, datanucleus or something like that. But with small private projects this will take over 80% of the worktime.

对于公司的大项目,我会使用 hibernate、ibatis、datanucleus 或类似的东西。但是对于小型私人项目,这将占用 80% 以上的工作时间。

I also found "simpleORM" but this one requires to code data-related stuff pretty hardly into the data-model classes. I don't really like that style so this is no option for me.

我还发现了“simpleORM”,但这需要将与数据相关的东西几乎编码到数据模型类中。我不是很喜欢那种风格,所以这对我来说是没有选择的。

Do you have a suggestion for some library which simply takes my objects and saves / loads them as they are or with very little configuration?

您是否对某些库有任何建议,该库只是获取我的对象并按原样或很少配置保存/加载它们?

回答by Gray

You could try ORMLite, which was designed as a simple replacement for hibernate and iBatis. I'm the main author. It supports a number of JDBC databases and has an Android backend. Here is the getting started section of the manual which has some code examples.

您可以尝试ORMLite,它被设计为 hibernate 和 iBatis 的简单替代品。我是主要作者。它支持许多 JDBC 数据库并有一个 Android 后端。这是手册的入门部分,其中包含一些代码示例。

http://ormlite.com/docs/getting-started

http://ormlite.com/docs/getting-started

Here also are working examples of simple usage patterns.

这里还有简单使用模式的工作示例。

http://ormlite.com/docs/examples

http://ormlite.com/docs/examples

回答by Thomas

You could just serialize your objects into a file/database whatsoever.

您可以将对象序列化为任何文件/数据库。

If you want to define the mapping then you'd have to go for more configuration and the standard OR mappers out there (like Hibernate) don't really add that much on top.

如果您想定义映射,那么您必须进行更多配置,并且那里的标准 OR 映射器(如 Hibernate)并没有真正添加那么多。

回答by mmazur

You could try xstream. It's really simple OXM library working without upfront configuration.

你可以试试xstream。这是非常简单的 OXM 库,无需预先配置即可工作。

Sample code:

示例代码:

XStream xstream = new XStream();
// marshalling
String xml = xstream.toXML(domainObject);
// unmarshalling
domainObject = xstream.fromXML(xml);

回答by ccleve

Try Norm. It's a lightweight layer over JDBC. It adds almost zero overhead to JDBC calls and is very easy to learn.

尝试规范。它是 JDBC 之上的一个轻量级层。它几乎为 JDBC 调用增加了零开销,并且非常容易学习。

回答by arbocdi

U could try SnakeORM http://sourceforge.net/p/selibs/wiki/Home/It doesnt have many runtime dependencies, uses JPA annotations and follows DAO pattern.

你可以试试 SnakeORM http://sourceforge.net/p/selibs/wiki/Home/它没有很多运行时依赖,使用 JPA 注释并遵循 DAO 模式。

Disclosure: I am the author of this project

披露:我是这个项目的作者

回答by Joel

For relational database persistence try one of the JPAimplementations, such as OpenJPA.

对于关系数据库持久性,请尝试其中一种JPA实现,例如OpenJPA

The setup overhead is minimal. You can let JPA to create your schema & tables for your from your object definitions, so you don't need to hand crank any sql. All you need to supply is some annotations on your entities and a single config file, persistence.xml.

设置开销很小。您可以让 JPA 根据您的对象定义为您创建架构和表,因此您无需手动启动任何 sql。您需要提供的只是实体上的一些注释和一个配置文件persistence.xml。

回答by Jeff Miller

You may want to consider www.sormula.org. Minimal programming/annotations and simple learning curve. It uses standard SQL and JDBC so will work with any relational db.

您可能需要考虑 www.sormula.org。最少的编程/注释和简单的学习曲线。它使用标准 SQL 和 JDBC,因此适用于任何关系数据库。

回答by mvlcek

You can also use jEasyORM (http://jeasyorm.sourceforge.net/). In most cases it automatically maps objects to database tables with no need for configuration.

您还可以使用 jEasyORM ( http://jeasyorm.sourceforge.net/)。在大多数情况下,它无需配置即可自动将对象映射到数据库表。

回答by Java Drinker

Well if you want an ORM, then that implies that you want to map objects to tables, columns to fields etc. In this case, if you want to avoid the hassle of bigger ORM implementations, you could just use plain old JDBC, with simple DataAccessor patterns. But then this does not translated to XML directly.

好吧,如果你想要一个 ORM,那么这意味着你想要将对象映射到表、列到字段等。在这种情况下,如果你想避免更大的 ORM 实现的麻烦,你可以使用简单的旧 JDBC,简单的数据访问器模式。但是这并没有直接转换为 XML。

If you want to just persist the object somewhere, and only care about "understanding" the object in Java, then serialization is a simple effective method, as Thomasmentioned earlier.

如果你只想将对象持久化到某个地方,而只关心在 Java 中“理解”对象,那么序列化是一种简单有效的方法,正如前面Thomas提到的。

回答by cosbor11

Onyx Databaseis a very feature rich Java NoSQL database alternative. It's pure java with several persisting modes (caching, embedded-database, save-to-remote, and save-to-remote-cluster. It has an embedded ORM, and is probably the easiest persistence API I've used.

Onyx 数据库是一个功能非常丰富的 Java NoSQL 数据库替代品。它是具有多种持久化模式(缓存嵌入式数据库保存到远程保存到远程集群)的纯 Java 。它具有嵌入式 ORM,并且可能是我使用过的最简单的持久化 API。