0

I have two EntityManagers for two DataSources with two Services, Repositories and some entities.

LocalContainerEntityManagerFactoryBean masterEntiryManager;
LocalContainerEntityManagerFactoryBean replicaEntiryManager;
...
MasterBrickRepository masterBrickRepository;
ReplicaBrickRepsoitory replicaBrickRepository;
...
MasterBrickService masterBrickService;
ReplicaBrickService replicaBrickService;
...
MasterBrcik masterBrick;
ReplicaBrick replicaBrick;

at the moment, I implement CRUD as below:

masterBrickService.save(masterBrick);
replicaBrickService.findAll();

This is very hard when number of Entity growing up! I am not sure if that can be handled by AOP with user annotation? is this possible and how can I do it?

BrickService brickService;
...
Brcik brick;
...
@Master
brickService.save(brick);

@Replica
brickService.findAll();
mikezang
  • 2,291
  • 7
  • 32
  • 56
  • I don't understand what you're trying to achieve. Mind elaborating a bit more by editing your question? – Nándor Előd Fekete Feb 01 '16 at 14:55
  • I have two entity managers for two data sources, so that I use two repositories and services. I want to know if I can only use one service and switch one of repositories or entity managers, may I make sense? – mikezang Feb 02 '16 at 13:44
  • If the two models and the services you build upon them are completely identical, I think it's probably a good idea to have only one service API and make the underlying entity manager configurable at construction time. So you don't have to implement the same API twice. With spring you could differentiate between the two via a `@Qualifier`. – Nándor Előd Fekete Feb 02 '16 at 14:21
  • Yeah, like you said I mean the same entity in two services and datasources. By the way, can you show me sample and I will test it, I will tell you to answer my question if I got what I want. – mikezang Feb 02 '16 at 14:29

0 Answers0