title: Modify JPA schema at runtime with EclipseLink running on JBoss
body: <p>I am new to JPA and JBoss, so sorry in advance if this is a stupid question.</p>
  
  <p>I have application running on JBoss using EclipseLink that retrieves entities from various databases based on a JPQL string. This is working great, except one database contains multiple schema's. I would like to be able to specify which schema to use, at runtime, and select all entities that belong to that schema, without modifying the JPQL string. </p>
  
  <p>To further complicate things, I would also like to join across schema's, in the same query. In this case, the JPQL query could change, or parameters could be set which specifies each entities schema.</p>
  
  <p>After some searching I came across this:</p>
  
  <p><a href="https://stackoverflow.com/questions/906671/jpa-how-do-i-specify-the-table-name-corresponding-to-a-class-at-runtime">JPA: How do I specify the table name corresponding to a class at runtime?</a></p>
  
  <p>Which has a solution using ASM that dynamically modifies the Table annotation. I have tried to use this to modify the Table annotation's schema property but for the life of me I cannot get it to work; it seems that Eclipse Link uses a different class loader to init the entity classes that I don't know how to access and thus changing the annotation has no effect.</p>
  
  <p>Another solution is have multiple xml configuration files for each schema. It seems inelegant; when I add a new entity I have to remember to add it to every schema's xml file. I also do not know how I can make this join across multiple schema's.</p>
  
  <p>Is there any way of solving this problem? Am I missing something or is this pushing JPA beyond what it was intended for?</p>