title: Hibernate Many-To-One using other schema on DB2
body: <p>I am using hibernate-annotation (entitymanager) to handle my db2 databases using separate schema.</p>
  
  <p>My main schema is called "mainschema". It has a table for fileuploads.</p>
  
  <p>Then I have some other schema (schema1, schema2, schema3, schemaN).</p>
  
  <p>How can I tell the many-to-one relationship on the schemaN to refer to the filetable on "mainschema". If I open the connection, I tell which schema to use. But the many-to-one is still using that schema and the fileupload table is only available in the "mainschema"</p>
  
  <p>Thanks for help!</p>
  
  <p>EDIT:</p>
  
  <p>My fileupload hibernate bean using explicit the main schema:</p>
  
  <pre><code>@Entity
  @Table(name="DOKUMENT", schema="mainschema")
  </code></pre>
  
  <p>Then I have one schema for every client, have a look at here:
  The Schema is not set in the bean. It is set instead in time where the connection is opened.</p>
  
  <pre><code>@Entity
  @Table(name="SOMETABLE")
  </code></pre>
  
  <p>This table "SOMETABLE" is existing in every schema for every client.
  It refers to the dokument entity with an many-to-one</p>
  
  <pre><code>@Many-To-One
  @JoinColumn(name="DOKUMENT_ID")
  public Dokument getDokument() { return dokument }
  public void setDokument() { this.dokument = dokument }
  </code></pre>
  
  <p>Question can be closed. It is working without any changes, because hibernate is still using "mainschema" automaticly.</p>