title: JPA / Hibernate : schema generation with multiple persistence units
body: <p>I have an application that uses a set of JPA entities that are located in 2 different databases. I configured it with multiple persistence units.</p>
  
  <p>The problem is that I want to auto-generate the schema using schema-generation, and all the entities are created in both databases.</p>
  
  <p>I have in both PUs:</p>
  
  <pre><code>        &lt;property name="javax.persistence.schema-generation.database.action" value="drop-and-create"/&gt;
          &lt;property name="javax.persistence.schema-generation.create-source" value="metadata"/&gt;
          &lt;property name="javax.persistence.schema-generation.drop-source" value="metadata"/&gt;
  </code></pre>
  
  <p>And, yes, I want to use the metadata to get the entities automatically. I do not want to provide a manual script, because I would need to keep it up to date with the entities.</p>
  
  <p>Is there a way to mark which entity to be generated by which PU?</p>
  
  <p>-edit: please be aware that adding "schema" property on @Table does not resolve the problem, because each PU will try to create the same entity in the right schema, and there will be errors because the tables will already exist. </p>