use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.
the class EntityManagerSourceImplTest method multiple_persistence_units_include_unlisted_classes.
@Test
public void multiple_persistence_units_include_unlisted_classes() {
Exception exception = null;
try {
new EntityManagerSourceImpl(LoggerFactory.getLogger(EntityManagerSourceImplTest.class), new ClasspathResource("multiple-persistence-units-include-unlisted-classes.xml"), null, CollectionFactory.<String, PersistenceUnitConfigurer>newMap());
fail("Exception expected");
} catch (Exception e) {
exception = e;
}
assertNotNull(exception);
assertEquals(exception.getMessage(), "Persistence units 'TestUnit, TestUnit2' are configured to include managed classes that have not been explicitly listed. This is forbidden when multiple persistence units are used in the same application. Please configure persistence units to exclude unlisted managed classes (e.g. by removing <exclude-unlisted-classes> element) and include them explicitly.");
}
use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.
the class AppModule method configurePersistenceUnitInfos.
@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnitInfos(final MappedConfiguration<String, PersistenceUnitConfigurer> configuration) {
final PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {
@Override
public void configure(final TapestryPersistenceUnitInfo unitInfo) {
unitInfo.addManagedClass(User.class);
}
};
configuration.add(AppConstants.TEST_PERSISTENCE_UNIT, configurer);
final PersistenceUnitConfigurer configurer2 = new PersistenceUnitConfigurer() {
@Override
public void configure(final TapestryPersistenceUnitInfo unitInfo) {
unitInfo.addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test").addProperty("eclipselink.ddl-generation", "create-tables").addProperty("eclipselink.logging.level", "fine").addManagedClass(Thang.class);
}
};
configuration.add(AppConstants.TEST_PERSISTENCE_UNIT_2, configurer2);
}
use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.
the class EntityManagerSourceImpl method configureRemaining.
private void configureRemaining(List<TapestryPersistenceUnitInfo> persistenceUnitInfos, Map<String, PersistenceUnitConfigurer> remainingConfigurations) {
for (Entry<String, PersistenceUnitConfigurer> entry : remainingConfigurations.entrySet()) {
final PersistenceUnitInfoImpl info = new PersistenceUnitInfoImpl(entry.getKey());
final PersistenceUnitConfigurer configurer = entry.getValue();
configurer.configure(info);
persistenceUnitInfos.add(info);
}
}
use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.
the class JpaTestModule method configurePersistenceUnit.
@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnit(MappedConfiguration<String, PersistenceUnitConfigurer> cfg, final ObjectLocator objectLocator) {
PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {
@Override
public void configure(TapestryPersistenceUnitInfo unitInfo) {
unitInfo.transactionType(PersistenceUnitTransactionType.RESOURCE_LOCAL).persistenceProviderClassName("org.eclipse.persistence.jpa.PersistenceProvider").excludeUnlistedClasses(true).addProperty("javax.persistence.jdbc.user", "sa").addProperty("javax.persistence.jdbc.password", "sa").addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:jpatest").addProperty("eclipselink.ddl-generation", "create-or-extend-tables").addProperty("eclipselink.logging.level", "FINE").addManagedClass(ThingOne.class).addManagedClass(ThingTwo.class).addManagedClass(VersionedThing.class);
unitInfo.getProperties().put("javax.persistence.bean.manager", objectLocator.autobuild(TapestryCDIBeanManagerForJPAEntityListeners.class));
}
};
// cfg.add("jpatest", configurer);
cfg.add("TestUnit", configurer);
}
use of org.apache.tapestry5.jpa.PersistenceUnitConfigurer in project tapestry-5 by apache.
the class AppModule method configurePersistenceUnitInfos.
@Contribute(EntityManagerSource.class)
public static void configurePersistenceUnitInfos(final MappedConfiguration<String, PersistenceUnitConfigurer> configuration) {
final PersistenceUnitConfigurer configurer = new PersistenceUnitConfigurer() {
@Override
public void configure(final TapestryPersistenceUnitInfo unitInfo) {
unitInfo.addManagedClass(User.class);
}
};
configuration.add(AppConstants.TEST_PERSISTENCE_UNIT, configurer);
final PersistenceUnitConfigurer configurer2 = new PersistenceUnitConfigurer() {
@Override
public void configure(final TapestryPersistenceUnitInfo unitInfo) {
unitInfo.addProperty("javax.persistence.jdbc.driver", "org.h2.Driver").addProperty("javax.persistence.jdbc.url", "jdbc:h2:mem:test").addProperty("eclipselink.ddl-generation", "create-tables").addProperty("eclipselink.logging.level", "fine").addManagedClass(Thang.class);
}
};
configuration.add(AppConstants.TEST_PERSISTENCE_UNIT_2, configurer2);
}
Aggregations