用于仅插入/仅查询应用程序的 ORM 框架
我已经使用 Hibernate 多年了,从来没有遇到过任何问题,但我刚刚意识到我的大部分工作都涉及 CRUD 方法,其中我需要数据保持持久化并随意修改。
这样做的问题是,有人想要制作 2 个独立的应用程序,一个用于批量插入,另一个对插入的数据执行搜索。
由于持久性在这种情况下有点无用,因此团队希望不使用 Hibernate,而是在插入应用程序上使用原始查询,也许类似于
这是正确的选择吗?或者我怎样才能说服他们使用 Hibernate,而不是“它是我最喜欢的 orm 框架”?或者是否还有其他尚未考虑的解决方案?
I've been using Hibernate for years and never have a problem with it, but just realized most of my work involved a CRUD approach, where I needed data to stay persisted and modified at will.
The problem with this is that there is people who want to make 2 separate apps, one that bulk inserts and another that performs search on the inserted data.
Since the persistence is a bit useless in this case, the team wants to not use Hibernate but to use raw queries on the insert app and maybe something like jOOQ on the query app.
Is that the right call? or how could I convince them to use Hibernate, other than "its my favourite orm framework"? Or are there even other solutions that haven't been taken into consideration?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
免责声明:我是 jOOQ 的创建者,因此,这个答案略有偏见。
jOOQ 是专门为您的同事提到的用例而设计的。在您的项目中,您没有执行 OLTP (CRUD) 而是 OLAP,这在很多方面都是 jOOQ 的一个非常好的用例。 jOOQ 鼓励使用 OLAP 功能,例如窗口函数、数据透视表、递归查询、存储过程、数组和非嵌套数组等。jOOQ 还支持 13 种不同的数据库,其中包含您想要避免的所有 SQL 兼容性细微差别。一些示例:
LIMIT .. OFFSET
/TOP .. START AT
等子句如何映射到数据库?不过,Hibernate 也很好地涵盖了所有这些兼容性方面。所以你的问题归结为:
你想使用Hibernate吗?它不是完美的技术选择,但你很了解它,因此可以估计风险?如果团队中的每个人都了解并喜欢 Hibernate,并且几乎没有时间学习新东西,那么这就是要走的路。
或者您想使用可能更合适的不同框架,但您不太了解它,因此无法估计所有风险?如果您是唯一支持 Hibernate 并且有时间学习新框架的人,这可能是一种选择。您可能需要考虑的其他框架:
或者您可以混合技术并使用 Hibernate 进行更简单的查询,使用普通 SQL / jOOQ / Spring / myBATIS / 等进行更复杂的查询。
或者您可以使用存储过程(例如,如果您使用 Oracle,则在 PL/SQL 中)处理批量处理和 OLAP 查询并让数据库完成工作?如果您的团队中有优秀的 DBA 或数据库专家,这可能是一种可行的方法。
答案没有正确或错误之分。但你必须做出务实的决定。
Disclaimer: I'm the creator of jOOQ and thus, this answer is slightly biased.
jOOQ was designed precisely for the use case your coworkers mention. In your project, you're not doing OLTP (CRUD) but OLAP, which is a very good use case for jOOQ in many aspects. jOOQ encourages using OLAP features, such as window functions, pivot tables, recursive queries, stored procedures, arrays and unnested arrays, etc. jOOQ also supports 13 different databases with all the SQL compatibility subtleties that you want to avoid. Some examples:
LIMIT .. OFFSET
/TOP .. START AT
, etc clauses mapped to a database?All of these compatibility aspects are very well covered by Hibernate as well, though. So your question comes back down to this:
Do you want to use Hibernate which is not the perfect technology choice, but which you know well and thus can estimate the risks? This is the way to go if everyone on the team knows and likes Hibernate and there is little time to learn new things.
Or do you want to use a different framework that might be more suitable, but you do not know it well and thus cannot estimate all the risks? This might be the way to go if you're the only one in favour of Hibernate and you have the time to learn new frameworks. Other frameworks you might want to consider:
Or you can mix technologies and use Hibernate for simpler queries and plain SQL / jOOQ / Spring / myBATIS / etc. for more complex ones.
Or can you handle bulk processing and OLAP querying using stored procedures (e.g. in PL/SQL if you're using Oracle) and let the database do the work? This might be the way to go if you have a good DBA or database-specialist on your team.
There is no right or wrong answer. But you will have to make a pragmatic decision.
Hibernate 是一种对象关系映射。如果他们只对原始数据流进行批量插入和报告,也许他们不需要任何对象表示。如果他们需要某种数据的对象表示,Hibernate 会派上用场。
Hibernate is an Object Relational Mapping. If they only do bulk inserts and reporting on raw data streams, maybe they don't need any object representation. Hibernate will come in handy if they need some sort of object representation of their data.
这是很有可能的。 Hibernate 可以很好地处理由其他应用程序同时更新的数据库。唯一的问题是 Hibernate 的内部缓存超时。这意味着数据库中更新记录与 Hibernate 查看更新数据之间可能存在轻微延迟(几分钟)。我相信这是可以配置的。
任何关于选择 Hibernate 而不是 JooQ 的争论都将成为应用程序如何概念化数据的方式之一。 Hibernate 将数据的行表示抽象为对象。有些程序员不喜欢这样,更喜欢手动完成。这可能是他们想要使用 JooQ 的原因,因此您需要与他们讨论应用程序结构。
This is very possible. Hibernate plays very well with databases that are simultaneously updated by other applications. The only gotcha is Hibernate's internal caching timeout. This means that there could be a slight delay (couple of minutes) between a record being updated in the database and Hibernate seeing the updated data. I believe this is configurable.
Any argument for preferring Hibernate over JooQ is going to be one of how the application conceptualises the data. Hibernate abstracts the row representation of the data into objects. Some programmers don't like that and prefer to do it by hand. This might be the reason they want to use JooQ, so you need to talk to them about application structure.
sormula 是一个支持 CRUD 的 ORM。您可以将 JDBC 与 sormula 混合使用。它不进行批量插入,但它确实有 insertAll(java.util.Collection) 插入对象集合。
sormula is a CRUD-ready ORM. You can mix JDBC with sormula. It does not do bulk inserts but it does have insertAll(java.util.Collection) to insert a collection of objects.