# Several Schemas X ManyToOne

**URL:** https://discourse.hibernate.org/t/several-schemas-x-manytoone/1189
**Category:** Hibernate ORM
**Created:** [August 6, 2018, 7:09pm UTC](https://discourse.hibernate.org/t/several-schemas-x-manytoone/1189 "2018-08-06T19:09:30Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![WOSouza](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/wosouza/32/256_2.png) [@WOSouza](https://discourse.hibernate.org/u/WOSouza)
#### Post date: [August 6, 2018, 7:09pm UTC](https://discourse.hibernate.org/t/several-schemas-x-manytoone/1189/1 "2018-08-06T19:09:30Z")

</div>

My scenery:

I have a project that uses three different schemas in MYSQL DataBase:  
PlanAd\_1  
PlanAd\_files\_1  
PlanAd\_log\_1

I would like to have in this same project, in the same instance of MYSQL, three other schemes:  
PlanAd\_2  
PlanAd\_files\_2  
PlanAd\_log\_2

And, being able to map this situation through Hibernate annotations, knowing that for each set of schemas a WAR file (application) will be associated.

WAR\_1 for PlanAd\_1; PlanAd\_files\_1; PlanAd\_log\_1  
WAR\_2 for PlanAd\_2; PlanAd\_files\_2; PlanAd\_log\_2

I can even set the value of hibernate.default\_schema in my JPA configuration file,  
but there is a problem that occurs in the passage between MANYTOONE relationships for example.

If I have one table in PlanAd\_1 and one in PlanAd\_Files\_1, and there is a ManyToOne relationship between them

Entity  
Table (name = “protocol\_name”)

A table inside PlanAd\_Files\_1 has an attribute:

ManyToOne  
JoinColumn (name = “Destination\_id”)  
private Destination first destination;

which I point to with the Target table that is in the PlanAd\_1 schema.  
When doing the mapping Hibernate can not understand that the Target table is in the other schema PlanAd\_1  
and tries to locate it within the schema of the table “protocol\_name”, causing a table error not found.

How can I indicate for this relation of ManyToOne, in which schema to look for another table, or another side of the N-to-1 relation.

---

<div class="post-metadata">

### Author: ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)
#### Post date: [August 7, 2018, 12:33pm UTC](https://discourse.hibernate.org/t/several-schemas-x-manytoone/1189/2 "2018-08-07T12:33:15Z")

</div>

First of all, MySQL does not support schemas. It only supports catalogs.

So, I suppose you have multiple catalogs there. You should use the `hibernate.default_schema` property which should work for associations as well. If it does not, you need to [replicate the issue](http://in.relation.to/2018/06/04/best-way-write-hibernate-orm-issue-test-case/), and send us a Pull Request that demonstrates it.

Otherwise, you can use XML files instead of annotations and supply the right catalog-specific mappings at build time, as explained in [this article](https://vladmihalcea.com/how-to-replace-the-table-identifier-generator-with-either-sequence-or-identity-in-a-portable-way/).
