JPA和数据库Flex字段 [英] JPA and database Flex fields

查看:174
本文介绍了JPA和数据库Flex字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Flex字段是用于在客户站点更改表格的术语,以向表中添加额外的列,以保存关于该表的实体的自定义信息。我想知道有没有人用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.

推荐答案

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

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?

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

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.

如果希望更改现有表,那将更复杂,您需要更新也可以通过编辑orm.xml和重新部署应用程序,或者在SessionCustomizer或DescriptorCustomizer中添加映射来进行JPA映射。 EclipseLink还支持VIRTUAL AccessMode,允许将列映射到属性而不是字段或get / set方法。

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还提供更多动态解决方案,将动态实体映射到表,而不需要类。

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

请参阅
http://维基。 eclipse.org/EclipseLink/Examples/JPA/Dynamic

这篇关于JPA和数据库Flex字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆