Is it possible to change the entity-table mapping at runtime with Eclipselink? I have a Entity-View mapping defined with annotations. Now I have the business requirement: "If these Views are empty, try the underlying table". Thus I have to switch from the view to the underlying table.
The view is just a SELECT on the table with some restrictions.
When do you need to check if the view is empty?
If it can be done one time at start-up, you could just put this check in a SessionCustomizer and alter the ClassDescriptor's table.
If you need to do this every time you query it, then this is much more odd. You could define a MappedSuperclass and two subclasses, one mapped to the view and one to the table, then decide in your application which to use.
You could also define another view that gives you the result that you wish.
It is possible to get the ClassDescriptor from the Session at runtime and change it, but this is normally a bad idea, as other clients/threads can be using the descriptor/session at the same time.
Or just always map to the table, and filter what is relevant in your query (or an additional join criteria) instead of using the view.