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:
@Entity public class Order{ .... private Integer customerId; @Transient private Customer customer; ... }
and bind transient Customer every time I load Order object by calling remote service. So for example in my OrderServiceImpl
@Transactional public Order getOrder(Integer id){ Order order = orderDao.get(id); order.setCustomer(customerRemoteService.getCustomerById(order.getCustomerId())); return order; }
I wonder if you can give me comments or better solutions!
Thank you very much!!!!! Marco