How can I dynamically select the database schema used? I know I can
hardcode the schema name into the mapping configuration. Furthermore, if I use plain SQL, I can use the dot-notation (e.g., select * from myschema.mytable ...). However, what I need is to do the latter with the hibernate-mapped data objects, e.g.:
"SELECT p FROM myschema.com.mycom.myapp.data.Person p"
But it does not work; it says "unknown mapping myschema.com.mycom.myapp.data.Person", so it assumes the myschema is part of the package name.
The reason why I need this kind of functionality is because the same query is supposed to perform a JOIN between two tables in different schemas. An example could be:
"SELECT p FROM MYSCHEMA.com.mycom.myapp.data.Person p
WHERE p.id IN (SELECT o.ID FROM OTHERSCHEMA.com.mycom.myapp.data.Person o)"
or equivalent. You get the idea. How to accomplish this?
Thank you.
|