具有用户定义属性的 Hibernate 实体

发布于 2024-08-10 06:41:58 字数 94 浏览 3 评论 0原文

有人可以给我一些关于建模具有一些已知属性的休眠实体的提示,而大多数属性是由系统用户定义的(在系统的初始设置期间)

我需要能够稍后搜索这些用户定义的属性时间点。

Can someone please give me some tips on modeling hibernate entities that have some known attributes while the majority are defined by the user of the system (during initial setup of the system)

I need to be able to search on these user defined attributes at a later point in time.

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

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

发布评论

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

评论(1

断念 2024-08-17 06:41:58

首先,您需要决定如何对此进行建模。两种最常见的方法是Entity-Attribute-Value模型和行建模。

前者使用 Hibernate 更容易处理;后者更容易处理。然而,根据您打算使用的搜索条件,它的性能可能(非常)差。某些条件根本无法转换为单个 SQL 查询。

后者更难实现,因为您既要考虑在运行时动态更改数据库模式,又要更改 Hibernate 的配置以匹配。看看我对如何映射动态创建的答案如果您选择走这条路线,请参阅 Hibernate 中的表了解更多详细信息。

另一种可能的选择是使用 Hibernate 对 XML 映射的支持< /a> 但是,同样,根据您的搜索条件和底层数据库支持的 XML 功能(如果有),这可能是也可能不是一个可行的选择。

First of all you'll need to decide on how you're going to model this. Two most common approaches are Entity-Attribute-Value model and row modeling.

The former is (much) easier to deal with using Hibernate; however depending on the search criteria you intend to use it may perform (very) poorly. Certain criteria can not be translated to a single SQL query at all.

The latter is harder to implement as you're looking at both altering your database schema dynamically at runtime and changing Hibernate's configuration to match. Take a look at my answer to How to map dynamically created table in Hibernate for more detail if you choose to go this route.

Another possible alternative is to use Hibernate's support for XML mapping but, again, depending on your search criteria and XML functionality (if any) supported by your underlying database this may or may not be a viable option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文