JPA and database Flex fields

穿精又带淫゛_ 提交于 2019-12-06 15:04:47

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!