A pragmatic solution is copy the Hibernate session source implementation in your applications sourcefolder. Use the same Name and package namens. Actually your source folder Version overwrites the Version in the hibernate module since your code is in the parent classloader.
Now you habe complete control of the construction of sessions and session factory. So of you habe a configuration Problem you can fix it their. Also you can use the same with that session source interface. Add additional methods if you need. And of cause you can also alter and extend hibernate manager to provide two different session objects. Look at the hibernate module and the use of marker interfaces. So you can habe as man distinct sessions per thread from AS many factories AS you wish. But hey that just the pragmatic way. Maybe there is a better one. Cheers, Martin Kersten, Germany Am 24.09.2013 16:57 schrieb "josete" <mual...@gmail.com>: > Hi everyone ! > > I'm facing a problem on trying to get Tapestry 5.3.7 to use multiple JPA > database for same application. > > I do have an administration console with a big options menu. > > In order to speedup some of the functionality, i defined an extra database > that will be queried against. > > My problem lies in that looks like 2 EntityManagers can't manage the same > entities. > > I've check tapestry-jpa src-code, and the problem? lies in here : > > Class JPAModule.java > <pre> > @Contribute(ApplicationStateManager.class) > public static void provideApplicationStateContributions( > final MappedConfiguration<Class, ApplicationStateContribution> > configuration, > final EntityManagerSource entityManagerSource, > > @Symbol(JpaSymbols.ENTITY_SESSION_STATE_PERSISTENCE_STRATEGY_ENABLED) > final boolean entitySessionStatePersistenceStrategyEnabled) > { > > > if (!entitySessionStatePersistenceStrategyEnabled) > return; > > for (final PersistenceUnitInfo info : > entityManagerSource.getPersistenceUnitInfos()) > { > final EntityManagerFactory emf = > entityManagerSource.getEntityManagerFactory(info.getPersistenceUnitName()); > > final Metamodel metamodel = emf.getMetamodel(); > > for (EntityType<?> entity : metamodel.getEntities()) > { > configuration.add(entity.getJavaType(), new > ApplicationStateContribution(JpaPersistenceConstants.ENTITY)); > } > > } > } > </pre> > > As you can see, for every entity, tapestry is adding the entity type to the > share configuration. > As Entity X is already managed by configuration for Database1, when same > Entity X from Database2 is added to the configuration, it just throws an > Exception. > > How can i fix this ? > > I do REALLY need the same instance managed by both instances. > > Thanks a lot. >