开发者

JPA and database Flex fields

开发者 https://www.devze.com 2023-02-14 01:06 出处:网络
\'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

'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开发者_StackOverflow中文版 other approaches.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消