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.firstname
should be persisted from LDAPTeacher.lastname
should be persisted from LDAPTeacher.email
should be persisted from PostgreSQLStudent.firstname
should be persisted from PostgreSQLStudent.lastname
should be persisted from LDAPStudent.email
should 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.firstname
should be persisted from PostgreSQLTeacher.lastname
should be persisted from PostgreSQLTeacher.email
should be persisted from PostgreSQLStudent.firstname
should be persisted from PostgreSQLStudent.lastname
should be persisted from LDAPStudent.email
should 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.