Wildfly 10 / JPA
blackhm May 26, 2016 12:22 PMHello,
I actually trying to setup an EntityManagerFactory with Persistence.createEntityManagerFactory() method, here an arquillian test :
@RunWith(Arquillian.class) @ApplicationScoped public class EMTest extends TestCase { @Deployment public static WebArchive deployment(){ BeansDescriptor beanDescriptor = Descriptors.create(BeansDescriptor.class); PersistenceDescriptor persistenceDescriptor = Descriptors.create(PersistenceDescriptor.class); persistenceDescriptor .version("2.1") .createPersistenceUnit() .name("MyDB") .jtaDataSource("java:jboss/datasources/MyDS") .jarFile("lib/entities.jar") .getOrCreateProperties() .createProperty() .name("hibernate.hbm2ddl.auto") .value("create-drop") .up() .createProperty() .name("hibernate.dialect") .value("org.hibernate.dialect.H2Dialect"); WebArchive webArchive = ShrinkWrap .create(WebArchive.class) .addAsWebInfResource(new StringAsset(beanDescriptor.exportAsString()), "beans.xml") .addAsWebInfResource(new StringAsset(Descriptors.create(WebAppDescriptor.class).exportAsString()), "web.xml") .addAsResource(new StringAsset(persistenceDescriptor.exportAsString()), "META-INF/persistence.xml") .addAsLibraries( Maven .configureResolver() .loadPomFromFile("pom.xml") .importRuntimeAndTestDependencies() .resolve() .withTransitivity() .as(JavaArchive.class) ); return webArchive; } @Inject UserTransaction ut; @Transactional public EntityManagerFactory getEMFactory(){ return Persistence.createEntityManagerFactory(null); } @Test public void test() throws Exception { getEMFactory(); } }
The Weld/Hibernate bootstrap show the persistence unit created and schema created. All seems good. But ...
When i look at the console, i see these info when Persistence.createEntityManagerFactory() method is called:
testing-remote-as_1 | 16:12:27,819 DEBUG [org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl] (default task-22) Incoming config yielded no classloaders; adding standard SE ones
testing-remote-as_1 | 16:12:27,823 DEBUG [org.hibernate.jpa.internal.util.LogHelper] (default task-22) PersistenceUnitInfo [
testing-remote-as_1 | name: MyDB
testing-remote-as_1 | persistence provider classname: null
testing-remote-as_1 | classloader: null
testing-remote-as_1 | excludeUnlistedClasses: false
testing-remote-as_1 | JTA datasource: java:jboss/datasources/MyDS
testing-remote-as_1 | Non JTA datasource: null
testing-remote-as_1 | Transaction type: JTA
testing-remote-as_1 | PU root URL: vfs:/content/b779e03d-6283-4eb2-9996-bf987733602b.war/WEB-INF/classes
testing-remote-as_1 | Shared Cache Mode: null
testing-remote-as_1 | Validation Mode: null
testing-remote-as_1 | Jar files URLs [
testing-remote-as_1 | file:lib/entities.jar]
testing-remote-as_1 | Managed classes names []
testing-remote-as_1 | Mapping files names []
testing-remote-as_1 | Properties [
testing-remote-as_1 | hibernate.dialect: org.hibernate.dialect.H2Dialect
testing-remote-as_1 | hibernate.hbm2ddl.auto: create-drop]
The first line seems to indicate a classloader not provided, as confirmed by info following.
The pb is that entities from the jar 'entities.jar' are not load into the entitymanagerfactory (checked), there is an exception in the logs :
testing-remote-as_1 | 16:12:27,828 TRACE [org.hibernate.boot.archive.internal.ArchiveHelper] (default task-22) JAR URL from URL Entry: jar:file:///content/b779e03d-6283-4eb2-9996-bf987733602b.war/WEB-INF/classes!/lib/entities.jar >> file:/content/b779e03d-6283-4eb2-9996-bf987733602b.war/WEB-INF/classes
testing-remote-as_1 | 16:12:27,828 WARN [org.hibernate.orm.url] (default task-22) HHH10000002: File or directory named by URL [file:/content/b779e03d-6283-4eb2-9996-bf987733602b.war/WEB-INF/classes] could not be found. URL will be ignored: java.io.FileNotFoundException: /content/b779e03d-6283-4eb2-9996-bf987733602b.war/WEB-INF/classes (No such file or directory)
testing-remote-as_1 | at java.util.zip.ZipFile.open(Native Method)
testing-remote-as_1 | at java.util.zip.ZipFile.<init>(ZipFile.java:220)
testing-remote-as_1 | at java.util.zip.ZipFile.<init>(ZipFile.java:150)
testing-remote-as_1 | at java.util.jar.JarFile.<init>(JarFile.java:166)
testing-remote-as_1 | at java.util.jar.JarFile.<init>(JarFile.java:103)
testing-remote-as_1 | at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.resolveJarFileReference(JarFileBasedArchiveDescriptor.java:165)
testing-remote-as_1 | at org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor.visitArchive(JarFileBasedArchiveDescriptor.java:51)
testing-remote-as_1 | at org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor.visitArchive(JarProtocolArchiveDescriptor.java:59)
testing-remote-as_1 | at org.hibernate.boot.archive.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:40)
testing-remote-as_1 | at org.hibernate.boot.model.process.internal.ScanningCoordinator.coordinateScan(ScanningCoordinator.java:75)
testing-remote-as_1 | at org.hibernate.boot.model.process.spi.MetadataBuildingProcess.prepare(MetadataBuildingProcess.java:98)
testing-remote-as_1 | at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.<init>(EntityManagerFactoryBuilderImpl.java:199)
testing-remote-as_1 | at org.hibernate.jpa.boot.spi.Bootstrap.getEntityManagerFactoryBuilder(Bootstrap.java:34)
testing-remote-as_1 | at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilder(HibernatePersistenceProvider.java:165)
testing-remote-as_1 | at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:114)
testing-remote-as_1 | at org.hibernate.jpa.HibernatePersistenceProvider.getEntityManagerFactoryBuilderOrNull(HibernatePersistenceProvider.java:71)
testing-remote-as_1 | at org.hibernate.jpa.HibernatePersistenceProvider.createEntityManagerFactory(HibernatePersistenceProvider.java:52)
As i can see the real path of the jar-file inside the persistence.xml seems to be resolved wrongly. I suppose that classloader can cause this since wildfly use a vfs.
Is there correct? Is there a property to use to configure the classloader used to load the entity manager factory?