用于只读 DB 的 java ORM

发布于 2024-09-14 19:52:40 字数 246 浏览 3 评论 0原文

我了解 hibernate,但我想知道是否有一个更轻的 ORM 引擎用于只读数据库。我的意思是,我不需要一些事务查询或更新一些记录。另一方面,我需要处理一些大的记录列表:

List<MyRecord> list= object.getMyRecords(); // list.size() > 1E7

这样的引擎是否存在? 非常感谢,

皮埃尔

I know hibernate but I wonder if there would be a lighter ORM engine for a read only database. I mean, I don't need some transactional queries or to update some records. On the other side, I need to handle some large list of records:

List<MyRecord> list= object.getMyRecords(); // list.size() > 1E7

Does such engine exist ?
Many thanks,

Pierre

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

从﹋此江山别 2024-09-21 19:52:40

你可以查看JIRM(是的,这是一个无耻的插件),它是专注于使用不可变对象的 ORM。

它位于 Spring JDBC 之上,因此,如果您使用 Spring,尝试它的风险非常低。

它还有非常好的 SQL 占位符模板不需要Spring。

您应该查看的另一个项目是 jOOQ

You can check out JIRM (yes, that is a shameless plug) which is an ORM focused on using immutable objects.

It sits right on top of Spring JDBC so, if you're using Spring, it's very low risk to try it.

It also has really nice SQL placeholder templates that do not require Spring.

Another project you should checkout is jOOQ.

一抹淡然 2024-09-21 19:52:40

我认为你应该考虑 MyBatis (IBatis 3) ORM 库。它满足从轻量级工作到一些大批量执行的要求。因此,它将非常适合您当前的需求,并且当您需要底层 ORM 库中的一些繁重工作时,它不会让您运气不好。

I think you should consider MyBatis (IBatis 3) ORM library. It fits the requirements from light-weight work to some heavy batch executions. So it'll fit your current needs very well and won't through you out of luck when you require some heavy-lifting work from your underlying ORM library.

墨落成白 2024-09-21 19:52:40

如果您正在寻找轻量级 ORM 框架,OrmLite 就是您的最佳选择。它可以让您避免设置 Hibernate 等更复杂的 ORM 框架的大部分开销。该框架的缺点是它不支持标准 JPA 注释,因此以后将此 ORM 替换为不同的 ORM 并不容易。

我建议尝试 OpenJPA 这是一个由 Apache 维护的符合 JPA 标准的 ORM 框架基础。它是Hibernate的主要竞争对手之一。它的设置确实需要更多的开销,但它的优点是,如果它不再满足您的需求,您可以在将来将其更换为不同的 JPA 兼容框架(例如 Hibernate)。

这两个框架也是开源的,这始终是使用它们的一个很好的理由。

If you are looking for a lightweight ORM framework, look no further than OrmLite. It allows you to avoid most of the overhead of setting up more complicated ORM frameworks like Hibernate. The downside to this framework is that it does not support standard JPA annotations so it would not be easy to swap this ORM out for a different one later on.

I would suggest trying out OpenJPA which is a JPA standard compliant ORM framework maintained by the Apache foundation. It is one of Hibernate major competitors. It does have a bit more overhead to setup but it has the advantage of allowing you to swap it out in the future for a different JPA compliant framework (like Hibernate) if it no longer suits your needs.

Both of these frameworks are Open Source as well which is always a good reason for using them.

爱你是孤单的心事 2024-09-21 19:52:40

大约一年前,我也在 lite ORM 中搜索了一个项目。并尝试了其中几个。我对所有解决方案都有点不满意,因为每个解决方案都试图朝某个方向前进。

Hibernate 非常庞大,当您只需要简单的解决方案时,它可能会带来额外的麻烦。目前我正在开发一个不错的项目,它在表格上使用了很少的自定义层。

您可能可以尝试使用 Active Record 或 Table Gateway 等一些模式,通过 JDBC 在数据库上实现一个小层。

任何 ORM 解决方案只是试图非常统一,并为您的项目添加额外的尾部。但是您可以创建自己的自定义无层解决方案 - 如果您的数据库具有预定义的表集并且不会经常更改其结构,那么这将特别有效。

I searched lite ORM too for one project about a year ago. And tried a couple of them. I was a bit unsatisfied with all solutions because each of them was trying to move in certain direction.

Hibernate is a huge and it can be a source of extra troubles when you want just simple solution. Currently I am working on the one nice project it uses little custom layer over tables.

You can probably try to implement a little layer over your database with JDBC using some patterns like Active Record or Table Gateway, etc.

Any ORM solution just tries to be very unified and ads extra tails to your project. But you can create your own custom layer-less solution - this will especially work fine if you database have predefined set of tables and doesn't change it's structure too often.

淡莣 2024-09-21 19:52:40

看看Ebeans,它是一个轻量级 ORM 工具:

  • 重用 JPA 注释(@Entity、@OneToMany .. .) 用于映射。
  • 使用Session Less架构(即具有比JPA更简单的API)。
  • 支持不可变值对象。
  • 允许使用ORM或关系功能
  • 声称提供良好的大型查询 支持

IMO 值得一看。

Have a look at Ebeans which is a light ORM tool:

  • Reuses JPA Annotations (@Entity, @OneToMany ...) for mapping.
  • Uses a Session Less architecture (i.e. has a simpler API than JPA).
  • Supports immutable Value Object.
  • Allows to use ORM or Relational features
  • Claims to provide good large query support

Worth the look IMO.

世俗缘 2024-09-21 19:52:40

Spring 的 SimpleJDBCTemplate 与结果映射器相结合,在只读场景中为我带来了奇迹,您不会获得 Hibernate 不必要的开销,所有伪 ORM 映射都捆绑在一起,这对于此类场景来说是真正的胜利。

Spring's SimpleJDBCTemplate combined with result mappers worked marvels for me in read only scenarios, you don't get the unneeded overhead of hibernate, all your pseudo-ORM mapping is bundled together, it is a true win for such scenarios.

濫情▎り 2024-09-21 19:52:40

如果您正在寻找轻量级 ORM,我会推荐 jORM。请注意,我的回答是有偏见的,因为我是该项目的贡献者之一。

我们决定编写一个轻量级替代方案的主要原因是(需要):

  • Hazzlefree 配置
  • 清晰的事务定义
  • 内存管理和速度
  • 简单的代码生成
  • 手动调整 SQL

简而言之;快速发展。

配置示例

DataSource dataSource = new DataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/moria");
dataSource.setUsername("gandalf");
dataSource.setPassword("mellon");

Database.configure("moria", dataSource); // now there's a named database

记录示例

@Jorm(database="moria", table="goblins", id="id")
public class Goblin extends Record {  
    public Integer getId() {
        return get("id", Integer.class);
    }
    public void setId(Integer id) {
        set("id", id);
    }
    public Integer getTribeId() {
        return get("tribe_id", Integer.class);
    }
    public void setTribeId(Integer id) {
        set("tribe_id", id);
    }
    public Tribe getTribe() {
        return get("tribe_id", Tribe.class);
    }
    public void setTribe(Tribe tribe) {
        set("tribe_id", tribe);
    }
    public String getName() {
        return get("name", String.class);
    }
    public void setName(String name) {
        set("name", name);
    }
}

映射查询示例

Goblin goblin = Record.findById(Goblin.class 42);

List<Goblin> goblins = Record.findAll(Goblin.class);Goblin bolg = Record.find(Goblin.class, new Column("name", "Bolg"));

自定义查询示例

Tribe tribe = new Tribe();
tribe.setId(1);
String name = "Azog";

Goblin azog = Record.select(
    Goblin.class,
    "SELECT * FROM goblins WHERE name = #1# AND tribe_id = #2:id#",
    name, // #1#
    tribe // #2#
);

Goblin bolg = Record.find(Goblin.class, "SELECT * FROM goblins WHERE name = #1#", "Bolg");

If you are looking for a lightweight ORM I would recommend jORM. Note that my answer is biased, since I'm one of the contributors to the project.

The main reasons why we decided to write a lightweight alternative are (the need for):

  • Hazzlefree configuration
  • Clear transaction definitions
  • Memory management and speed
  • Simple code generation
  • Hand tuned SQL

In short; rapid development.

Example configuration

DataSource dataSource = new DataSource();
dataSource.setDriverClassName("org.postgresql.Driver");
dataSource.setUrl("jdbc:postgresql://localhost:5432/moria");
dataSource.setUsername("gandalf");
dataSource.setPassword("mellon");

Database.configure("moria", dataSource); // now there's a named database

Example record

@Jorm(database="moria", table="goblins", id="id")
public class Goblin extends Record {  
    public Integer getId() {
        return get("id", Integer.class);
    }
    public void setId(Integer id) {
        set("id", id);
    }
    public Integer getTribeId() {
        return get("tribe_id", Integer.class);
    }
    public void setTribeId(Integer id) {
        set("tribe_id", id);
    }
    public Tribe getTribe() {
        return get("tribe_id", Tribe.class);
    }
    public void setTribe(Tribe tribe) {
        set("tribe_id", tribe);
    }
    public String getName() {
        return get("name", String.class);
    }
    public void setName(String name) {
        set("name", name);
    }
}

Example mapped queries

Goblin goblin = Record.findById(Goblin.class 42);

List<Goblin> goblins = Record.findAll(Goblin.class);Goblin bolg = Record.find(Goblin.class, new Column("name", "Bolg"));

Example custom queries

Tribe tribe = new Tribe();
tribe.setId(1);
String name = "Azog";

Goblin azog = Record.select(
    Goblin.class,
    "SELECT * FROM goblins WHERE name = #1# AND tribe_id = #2:id#",
    name, // #1#
    tribe // #2#
);

Goblin bolg = Record.find(Goblin.class, "SELECT * FROM goblins WHERE name = #1#", "Bolg");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文