I\'m trying to configure Spring+Hibernate+JPA for work with two databases (MySQL and MSSQL).
My datasource-context.xml:
If you follow this tutorial, http://www.javacodegeeks.com/2010/05/jboss-42x-spring-3-jpa-hibernate.html you can make the following changes to access two different databases:
for every DAO you want to access the second database include the following :
@Autowired
private EntityManagerFactory entityManagerFactoryDB2;
@PostConstruct
public void init() {
super.setEntityManagerFactory(entityManagerFactoryDB2);
}
Thats all!
On spring service classes, use the DAOs as usual!