Well, I may have figured out a way to get around this, but it is not pretty and is fragile should hibernate internals change (change clazz_ to something else), etc.
Code:
@Loader(namedQuery="Task.findByID")
@NamedNativeQueries(value = {
@NamedNativeQuery(
resultClass=Task.class,
name="Task.findByID",
query="SELECT t.*, 1 as clazz_ FROM active_tasks t " +
" WHERE t.task_id = :id " +
" UNION " +
" SELECT " +
" t.*, 2 as clazz_" +
" FROM" +
" completed_tasks t" +
" WHERE t.task_id = :id"
)
})
But, this performs much better for my scenario where the number of tables is small (2), but the quantity of data in them is large.
I would still like to know the "right" way to do this if there is one.
--Kevin