Jira issue originally created by user ire.ogunsina:
I have 2 classes, a Parent class, Person and a Child class Employee using Class Table Inheritance mapping strategy. The classes' corresponding tables exist in 2 separate database: Person table exists in database: dbOne and Employee table is in dbTwo.
The classes are like:
CREATE TABLE Employee (
id INT NOT NULL,
department VARCHAR(50) NOT NULL,
) ENGINE = InnoDB;
ALTER TABLE Employee ADD FOREIGN KEY (id) REFERENCES dbOne.Person(id) ON DELETE CASCADE
where the reference table name is prefixed with the database name.
The main problem is that when I call
On Person object, it flags an error:
Message: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbOne.Employee' doesn't exist . Apparently, the expectation is for the base class to persist its instance and be able to automatically persist the sub class as well. This problem is absent when the tables are in the same database- which indicates that the CTI structure expects the entity tables to be within the same database. The reverse is true if I call the entity manager (for dbTwo) to save an Employee object.
Is there a workaround for this bug/feature?
Comment created by ire.ogunsina:
It appears that ORM technologies are limited in their ability to generate SQL queries that interrogate multiple databases in a single SQL statement (unit of work). This largely may be due to the fact that the entity manager is restricted to one database. This limitation may be responsible for this behavior.
Comment created by @beberlei:
Yes, the EntityManager is focused on one database, not multiple.
There are two workarounds:
Issue was closed with resolution "Won't Fix"