EasyWeb4J allows applications to use multiple databases for persistence easily. it does not require excessive amount of configuration to set up an application this way in EasyWeb4J. It also does not penalize simple applications using single database by forcing extra configuration on them. Simple remains simple while the difficult got easier.
If your project needs to access more than one database for retrieving models, you need to edit (/src/main/resources/repositories.properties) to specify the available data sources. Each repository type specifies a key of their own followed by a comma separated list of data sources. The configuration and behavior specific to the currently supported persistence mechanisms are discussed below.
The key in repositories.properties used for Hibernate support is hibernate. Here is a sample configuration line in repositories.properties for specifying different Hibernate SessionFactories.
hibernate=sf1,sf2
When this line is present in repositories.properties, EasyWeb4J will look for these two class-path resources to build the session factories required.
These session factories can then be used in your HibernateRepository subclasses using the @UseSessionFactory annotation. Here is an example,
@UseSessionFactory("sf2") public class SampleRepository extends HibernateRepository<Sample> { }
The key in repositories.properties used for JPA support is jpa. Here is a sample configuration line in repositories.properties for specifying different JPA PersistenceUnits.
jpa=pu1,pu2
When this line is present in repositories.properties, EasyWeb4J will look for these two persistence units in /src/main/resources/META-INF/persistence.xml.
These PersistenceUnits can then be used in your JPARepository subclasses using the @UsePersistenceUnit annotation. Here is an example,
@UsePersistenceUnit("pu2") public class SampleRepository extends JPARepository<Sample> { }
Warning: EasyWeb4J currently does not use JTA for transaction management. Integration with JTA is planned in the near future. Hence, as of now it is not a good idea to access multiple data sources within the same request.