Reputation: 21186
I want to have two EntityManagerFactories (org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean
in this case), with each of them having their own data source and own set of persistent objects.
So somehow I need to be able to scope entities to a particular entity manager factory. I would prefer not to have to hard code the entity names into persistence.xml
.
Maybe there is some way of putting a filter on the class path scanner when JPA scans for entities? or some way of connecting an entity to a particular persistence unit.
Upvotes: 2
Views: 571
Reputation: 18796
Your 2 PUs would have identical classes(domain objects) but they are distinguished by PU name which you give to your 2 different factory beans and inject those into your respective DAOs. Now if you are using Hibernate as your JPA provider then you can define
<property name="hibernate.archive.autodetection" value="class,hbm" />
to have your factories automatically scan your classpath for your entities (Use class or hbm depending on whether you use annotations or hbm files) then you will not have to explicitly list out your classes.
Upvotes: 0
Reputation: 100706
Perhaps I misunderstood what you want, but...
Define your persistence units separately by specifying unique names for each. Specify said names for each of your LocalContainerEntityManagerFactoryBean
instances via persistenceUnitName
property.
Upvotes: 1