用于只读 DB 的 java ORM
我了解 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
你可以查看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.
我认为你应该考虑 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.
如果您正在寻找轻量级 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.
大约一年前,我也在 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.
看看Ebeans,它是一个轻量级 ORM 工具:
IMO 值得一看。
Have a look at Ebeans which is a light ORM tool:
Worth the look IMO.
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.
如果您正在寻找轻量级 ORM,我会推荐 jORM。请注意,我的回答是有偏见的,因为我是该项目的贡献者之一。
我们决定编写一个轻量级替代方案的主要原因是(需要):
简而言之;快速发展。
配置示例
记录示例
映射查询示例
自定义查询示例
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):
In short; rapid development.
Example configuration
Example record
Example mapped queries
Example custom queries