Announcement Announcement Module
No announcement yet.
Remote entity relationship with Spring and JPA Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remote entity relationship with Spring and JPA

    I have 2 databases. The first one is the db of our company ERP and the second one the db of my app.

    I need to working in my app with synched customers table data from ERP database. Now I synch the tables every hour with quartz job. In this way I have a local Customer table and I have no problem making a foreign key column in my Orders.

    In future, developing new apps, this strategy will not be a good solution (assumed that it is now..). For every app, working in this manner, I will have local copy of customer table and a synching procedure..

    So I'm thinking to implement a remote support application with spring-remoting with a remote interface in order to get customers. This remote application is connected to ERP database, and all my apps will call remote service to get data.

    Now my questions is:

    could it be a good approach or there are better way to implement this?

    how to reference the Customer entity in my Orders? Following this solution I don't have local Customer table anymore.. I think I can do in domain class:

    public class Order{
        private Integer customerId; 
        private Customer customer;
    and bind transient Customer every time I load Order object by calling remote service. So for example in my OrderServiceImpl

    public Order getOrder(Integer id){
        Order order = orderDao.get(id);
        return order;
    I wonder if you can give me comments or better solutions!

    Thank you very much!!!!!

  • #2
    I have a similar requirement. Can you please share how you ended up implementing this ?


    • #3

      I have solved using 2 datasource in my application.

      In the service layer, instead of get your entity from a remote service, you can get it from the second datasource. So your service will have two entityManager, the local one and the "remote" one.

      Hope this helps!