Java Micro ORM equivalent [closed]

痴心易碎 提交于 2019-12-02 14:16:50

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.

sql2o seems like a Dapper alternative - thin wrapper around 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

site - http://www.sql2o.org/

Here's a list of tools that "ease the pain" when interacting with simple JDBC:

And here's a list of tools that go a bit beyond simple JDBC, i.e. provide some ORM / ActiveRecord facilities

  • 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

Another interesting light ORM is JDBI. Here is Five minute intro

It has two alternative APIs:

Fluent 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 API where SQL statements are mapped to methods with declarative interfaces like this:

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

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.

This one doesn't seem to be mentioned here yet: dalesbred

Similar to sql2o and dapper...

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!