JPA 和数据库 Flex 字段

发布于 2024-10-19 23:20:27 字数 266 浏览 2 评论 0原文

“弹性字段”是一个术语,用于更改客户站点的表以向表添加额外的列以保存有关该表实体的自定义信息。我想知道是否有人处理过使用 jpa 支持这种机制,特别是 eclipselink。

我们希望这样做,因为我们允许根据这些客户指定字段中的值过滤基本行,并且将这些字段放在关联表中会导致与该辅助表的多个别名连接。

一个明显的方法(至少在我看来)是定义一个方面,将新字段注入实体对象,然后运行动态编织。

我想知道是否有人这样做过,是否有任何我没有看到的问题,或者关于其他方法的建议。

'Flex fields' is a term for altering a table at the customer site to add extra columns to a table to hold custom pieces of information about that table's entity. I was wondering if anyone has dealt with supporting this mechanism with jpa, specifically eclipselink.

We wish to do this because we allow filtering of the base rows based on values in these customer specified fields, and having these fields in an association table causes multiple alias joins to this auxilliary table.

An obvious approach (at least it would seem to me) would be to define an aspect(s) that injects the new fields into the entity object, and then run dynamic weaving.

I was wondering if anyone has done this, and if there are any problems i'm not seeing, or suggestions about other approaches.

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

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

发布评论

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

评论(2

旧时光的容颜 2024-10-26 23:20:27

那么,如果您将新字段注入实体中,您将如何在应用程序中使用这些字段?您还会更改应用程序/UI 的代码吗?

最简单的解决方案通常是在实体中拥有属性映射,这允许在运行时添加新属性,并允许应用程序/UI 访问和查询这些属性,以便可以呈现它们并允许编辑和显示。您可以使用 ElementCollection 或 OneToMany 将属性映射到属性表。

如果您希望更改现有表(这会更复杂),您还需要更新 JPA 映射,方法是编辑 orm.xml 并重新部署应用程序,或者在 SessionCustomizer 或 DescriptorCustomizer 中添加映射。 EclipseLink 还支持 VIRTUAL AccessMode,允许将列映射到属性而不是字段或获取/设置方法。

更强力的方法是更新对象模型代码和应用程​​序代码以利用新数据。

EclipseLink 还提供了更动态的解决方案,无需类即可将动态实体映射到表。

看,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Dynamic

So, if you inject new fields into your Entity how would you use these in your application? Would you also change your applications/UI's code?

The simplest solution is normally to have a Map of properties in your Entity, this allows new properties to be added at runtime, and allows for the application/UI to access and query these properties so that it can present them and allow editing and display. You can map the properties using an ElementCollection or OneToMany to a properties table.

If you wish the alter the existing table, that would be more complex, you would need to update the JPA mappings as well, either by editing the orm.xml and redeploying the application, or adding the mappings in a SessionCustomizer or DescriptorCustomizer. EclipseLink also supports a VIRTUAL AccessMode that allow mapping a column to a property instead of a field or get/set method.

A more brute force method is to update the object model code and the application code to make use of the new data.

EclipseLink also provides more dynamic solutions to map dynamic Entities to table without requiring classes.

See,
http://wiki.eclipse.org/EclipseLink/Examples/JPA/Dynamic

朮生 2024-10-26 23:20:27

我已经开始构建一个示例来说明如何将 EclipseLink 与可扩展模型(键值表或弹性列)一起使用。这是一项正在进行的工作,但我已经开始向示例 wiki 页面添加更多图表和示例代码:

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensible

这还包括使用上面提到的动态支持 James。

I have started building an example that illustrates how EclipseLink can be used with extensible models (key-values table or flex-columns). It is a work in progress but I have started adding more diagrams and sample code to the example wiki page:

http://wiki.eclipse.org/EclipseLink/Examples/JPA/Extensible

This also includes using the dynamic support James mentioned above.

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