Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Entity Inheritance from separate dbs?

 
Rj Ewing
Ranch Hand
Posts: 91
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it possible to extend an entity with the parent and child in separate databases? In our core system, we have entityA. A customer wants to add additional data to entityA. However this additional data will be stored in a separate database. Is it possible to use a jpa inheritance strategy for this? Or would this be better as 2 objects with a relationship? It would be nice to be able to directly access entityA methods when dealing with an entityAWithAdditionalData object, however this isn't necessary. If using a relationship, I assume I would need to call entityAWithAdditionalData.getEntityA().someMethodOfEntityA().
 
Roel De Nijs
Sheriff
Posts: 10662
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If the tables for both EntityA and the additional data for EntityA are stored in the same database but within different schemas you could definitely have one @Entity class and use the @SecondaryTable annotation. But based on your explanation that seems to be not the case. From many resources on the internet, it seems to be possible to have two different persistence units (each with their own data source). In this forum topic the same class is even reused. So I think it might be possible to use different persistence units, each with their own set of classes. I don't know if it is possible to have a relationship between both objects, because that would require one (or more) SQL query (queries) which retrieve data from several tables in different database servers. This SO question shows an example on how to configure different persistence units.

Hope it helps!
Kind regards,
Roel
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic