Search code examples
hibernatejboss5.xvfspersistence-unit

Load persistence unit with vfsfile (exploded JAR) on JBoss 5.1/Hibernate 3.3.2


I am looking for help to fix a problem to appeared when migrating from JBoss4 to JBoss5. There seems to be an issue with Hibernate support for VFS (introduced in JBoss5).

For modularity reason, multiple artifacts have persistence unit (pu) declaration. During deployment, all of them are merged into a single declaration similar to

Processing PersistenceUnitInfo [
    name: pu
    persistence provider classname: null
    classloader: org.jboss.web.tomcat.service.WebCtxLoader$ENCLoader@7a74fa
    Temporary classloader: org.springframework.instrument.classloading.SimpleThrowawayClassLoader@432f0a33
    excludeUnlistedClasses: false
    JTA datasource: com.xyz.jdbc.datasource.DelegatingDataSource@4546bcba
    Non JTA datasource: com.xyz.jdbc.datasource.DelegatingDataSource@4546bcba
    Transaction type: JTA
    PU root URL: vfszip:/<path>/<jar>/
    Jar files URLs [
        vfsfile:/<path>/<exploded jar>/
        vfsfile:/<path>/<exploded jar>/
        vfsfile:/<path>/<exploded jar>/
        vfszip:/<path>/<jar>/
        vfszip:/<path>/<jar>/
        vfszip:/<path>/<jar>/]
    Managed classes names []
    Mapping files names []
    Properties []

When enabling debug we can see that exploded jar are not scanned for annotation

[org.hibernate.ejb.packaging.AbstractJarVisitor] Searching mapped entities in jar/par: vfsfile:/<path>/<exploded jar>/
[org.hibernate.ejb.packaging.AbstractJarVisitor] Searching mapped entities in jar/par: vfsfile:/<path>/<exploded jar>/

Whereas compact JAR as scanned as expected

[org.hibernate.ejb.packaging.AbstractJarVisitor] Searching mapped entities in jar/par: vfszip:/<path>/<jar>/
[org.hibernate.ejb.packaging.AbstractJarVisitor] Filtering: com.xyz.batch.configuration.internal.impl.JobMetadataDocumentImpl$1$JobList
...

Resulting in QuerySyntaxException for query on Entities that were not found

org.hibernate.hql.ast.QuerySyntaxException: <EntityName> is not mapped 

Solution

  • According to Red Hat support it is not possible to use scanning with exploded JARs. Two solutions are available:

    • use Compact JARs and scanning works as expected
    • use Exploded JARs and declare all the @Entity with the < class /> tag in the persistence-unit.