I have some classes (Teacher, Student...) and I want to create objects from them with fields backed from more database sources in a configurable way. The information where the data source is for a particular class field can be different depending on deployment (configuration of the App). I want to have the information about database sources persisted as well. (I use Hibernate for persisting.)
Example of deployment 1:
Teacher.firstnameshould be persisted from LDAPTeacher.lastnameshould be persisted from LDAPTeacher.emailshould be persisted from PostgreSQLStudent.firstnameshould be persisted from PostgreSQLStudent.lastnameshould be persisted from LDAPStudent.emailshould be persisted from PostgreSQL
So there needs to be also information persisted in some DB that Teacher.firstname is backed in LDAP, Teacher.email in PostgreSQL etc.
Example of deployment 2:
Teacher.firstnameshould be persisted from PostgreSQLTeacher.lastnameshould be persisted from PostgreSQLTeacher.emailshould be persisted from PostgreSQLStudent.firstnameshould be persisted from PostgreSQLStudent.lastnameshould be persisted from LDAPStudent.emailshould be persisted from PostgreSQL
So there needs to be also information persisted in some DB that Teacher.firstname is backed in PostgreSQL, Student.lastname in LDAP etc.
I use Spring (not only) for DI and JPA (Hibernate) for persistency, but it's not so important. I am not looking for an answer how to configure 2 datasources in Spring/JPA, but rather how to design that problem generally.