Java Micro ORM 等价物
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6494938/
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
Java Micro ORM equivalent
提问by Kynth
What would be the closest equivalent in Java to a Micro ORM such as Dapper, PetaPoco, Massiveor CodingHorror?
Java 中与 Micro ORM(例如Dapper、PetaPoco、Massive或CodingHorror)最接近的等价物是什么?
采纳答案by Arnelism
I recommend Spring JDBC templates. While it's not a "true" ORM, it's a pleasure to use where Hibernate seems to be an overkill.
我推荐Spring JDBC 模板。虽然它不是一个“真正的” ORM,但在 Hibernate 似乎是一种矫枉过正的地方使用它是一种乐趣。
回答by tomaszkubacki
sql2o seems like a Dapper alternative - thin wrapper around JDBC
sql2o 似乎是一个 Dapper 替代品 - 围绕 JDBC 的瘦包装器
String sql =
"SELECT id, category, duedate " +
"FROM tasks " +
"WHERE category = :category";
Sql2o sql2o = new Sql2o(DB_URL, USER, PASS);
List<Task> tasks = sql2o.createQuery(sql)
.addParameter("category", "foo")
.executeAndFetch(Task.class);
github - https://github.com/aaberg/sql2o
github - https://github.com/aaberg/sql2o
site - http://www.sql2o.org/
回答by Lukas Eder
Here's a list of tools that "ease the pain" when interacting with simple JDBC:
以下是与简单 JDBC 交互时“减轻痛苦”的工具列表:
And here's a list of tools that go a bit beyond simple JDBC, i.e. provide some ORM / ActiveRecord facilities
这里有一个工具列表,这些工具有点超出了简单的 JDBC,即提供了一些 ORM/ActiveRecord 设施
- jOOQ(This one probably doesn't qualify as micro-ORM)
- JaQu
- ActiveJDBC(This one is more of an ActiveRecord API, than an ORM)
- MyBatis(This one focuses on SQL templating, but also has some mapping features)
- EBean
- jOOQ(这个可能不符合微 ORM 的条件)
- 贾曲
- ActiveJDBC(这更像是一个 ActiveRecord API,而不是一个 ORM)
- MyBatis(这个专注于SQL模板,但也有一些映射功能)
- 豆豆
回答by tomaszkubacki
Another interesting light ORM is JDBI. Here is Five minute intro
It has two alternative APIs:
它有两个替代 API:
Fluent API
流利的API
DBI dbi = new DBI(ds);
Handle h = dbi.open();
String name = h.createQuery("select name from something where id = :id")
.bind("id", 1)
.map(StringMapper.FIRST)
.first();
and SQL Object APIwhere SQL statements are mapped to methods with declarative interfaces like this:
和SQL 对象 API,其中 SQL 语句映射到具有声明式接口的方法,如下所示:
public interface MyDAO
{
@SqlUpdate("create table something (id int primary key, name varchar(100))")
void createSomethingTable();
}
DBI dbi = new DBI(ds);
MyDAO dao = dbi.open(MyDAO.class);
dao.createSomethingTable();
回答by Anaud Roger
Also checkout SimpleFlatMapper
It's a performant simple ResultSet to Object mapper. It just plug on top of jdbc and gives far better performance than Hibernate Ibatis or even sql2o. It easily integrate JdbcTemplate and provides constructor, setter and field injection.
它是一个高性能的简单 ResultSet 到 Object 映射器。它只是插在 jdbc 之上,并提供比 Hibernate Ibatis 甚至 sql2o 更好的性能。它可以轻松集成 JdbcTemplate 并提供构造函数、setter 和字段注入。