Java Micro ORM equivalent [closed]

余生颓废 提交于 2019-12-03 00:52:53

问题


What would be the closest equivalent in Java to a Micro ORM such as Dapper, PetaPoco, Massive or CodingHorror?


回答1:


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.




回答2:


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/




回答3:


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

  • Spring's JdbcTemplate
  • Apache DbUtils
  • JDBI
  • sql2o
  • persism

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



回答4:


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



回答5:


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.




回答6:


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

Similar to sql2o and dapper...



来源:https://stackoverflow.com/questions/6494938/java-micro-orm-equivalent

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