Reputation: 127
Let's say that i have the two Entities below :
@Entity
public class Employee {
String name;
@ManyToOne Department department;
}
@Entity
public class Department {
// persisted flieds ...
@OneToMany(mappedBy="department") Collection<Employee> employees;
}
and their corresponding tables are defined in two different schema oldSchema and newSchema with different content like this :
I'm working with the newSchema,
what i'm trying to do is to retrieve a Department entity object from the oldSchema with it's Collection of Employee from the oldSchema too.
What i'm getting is the Department Entity from the oldSchema but with the Collection of Employee from the newSchema.
The code i'm using:
Query q = entityManager.createNativeQuery("SELECT * FROM
oldSchema.Department d where d.departmentID = ?", Department.class);
q.setParameter(1, depID);
try{
Department d = (Department) q.getSingleResult();
}catch(exception){}
the object d contains Collection of Employees which are stored in newSchema.Employee
And this is due to the automatic schema evolution as explained here for ObjectDB https://www.objectdb.com/java/jpa/entity/schema which seems the same as for EclipseLink in my case , correct me if i'm wrong.
I'll apreciate your help!
Upvotes: 0
Views: 202
Reputation: 2923
Create more persistence units in persistence.xml or in orm.xml or whatever are you using. One persistence unit per schema. One entity manager / factory per schema.
Upvotes: 2