4 Replies Latest reply on Apr 12, 2010 6:09 AM by fharms

    hbm file is not picked up by the scanner

    fharms

      I'm having a bit of a puzzle with JBoss AS 5.1.0.GA and Hibernate. I have 3 jar files with contains persistence.xml file and hbm files located in META-INF\hibernatemapping and all packed in the root of the ear file, but there is one jar file where the hbm file is not scanned and I can't figure out what is wrong or how to investigate this.

       

      I have two other jar files which is working fine and the hbm files is detected and loaded.

       

      Any idea?

       

      myjarfile.jar:
           com\
                apc\
                     config\
                          settings\
                               server\
                                    persistence\Setting.class
           META-INF\
                MANIFEST.MF
                     hibernatemapping\settings.hbm.xml
      

       

      <?xml version="1.0"?>
      
      <!DOCTYPE hibernate-mapping PUBLIC
      
              "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
      
              "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
      
      <hibernate-mapping>
      
          <class name="com.apc.config.settings.server.persistence.Setting"
      
              table="settings" lazy="false" >
      
                  <id name="key" column="key" access="field" type="string"/>
      
                <property  name="value" column="value" type="text" />
      
          </class>
      
      </hibernate-mapping>
      
      

       

       

      Persistence.xml:


       <?xml version="1.0" encoding="UTF-8"?>
      
       <persistence xmlns="http://java.sun.com/xml/ns/persistence"
      
                    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      
                    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
      
                    version="1.0">
      
           <persistence-unit name="settingDataSource-server" transaction-type="JTA">
      
               <provider>org.hibernate.ejb.HibernatePersistence</provider>
      
               <jta-data-source>java:/jdbc/PostgresDS</jta-data-source>   
      
               <properties>
      
                   <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
      
                   <property name="hibernate.connection.release_mode" value="auto" />
      
                   <property name="hibernate.max_fetch_depth" value="2" />
      
                   <property name="hibernate.hbm2ddl.auto" value="update" />
      
                   <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect" />
      
                   <property name="org.hibernate.dialect.PostgreSQLDialect" value="update"/>
      
                   <property name="hibernate.transaction.manager_lookup_class" value ="org.hibernate.transaction.JBossTransactionManagerLookup" />
      
                   <property name="hibernate.show_sql" value="false" /> 
      
               </properties>
      
           </persistence-unit>
      
       </persistence>
      
      
      

       


       Here is the log result :
      
      
      13:19:49,636 INFO  [PersistenceUnitDeployment] Starting persistence unit persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
       13:19:49,637 DEBUG [Ejb3Configuration] Processing PersistenceUnitInfo [
      
      
           name: settingDataSource-server
      
      
           persistence provider classname: org.hibernate.ejb.HibernatePersistence
      
      
           classloader: BaseClassLoader@50725fe7{vfszip:/opt/jboss-5.1.0.GA/server/default/deploy/ISXO_Core.ear/}
      
      
           Temporary classloader: null
      
      
           excludeUnlistedClasses: false
      
      
           JTA datasource: org.jboss.resource.adapter.jdbc.WrapperDataSource@31960793
      
      
           Non JTA datasource: null
      
      
           Transaction type: JTA
      
      
           PU root URL: vfszip:/opt/jboss-5.1.0.GA/server/default/deploy/ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar/
      
      
           Jar files URLs []
      
      
           Managed classes names []
      
      
           Mapping files names []
      
      
           Properties [
      
      
               hibernate.connection.driver_class: org.postgresql.Driver
      
      
               hibernate.jndi.java.naming.factory.url.pkgs: org.jboss.naming:org.jnp.interfaces
      
      
               hibernate.cache.provider_class: org.hibernate.cache.HashtableCacheProvider
      
      
               hibernate.transaction.manager_lookup_class: org.hibernate.transaction.JBossTransactionManagerLookup
      
      
               hibernate.jndi.java.naming.factory.initial: org.jnp.interfaces.NamingContextFactory
      
      
               hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
      
      
               hibernate.max_fetch_depth: 2
      
      
               hibernate.jacc.ctx.id: com.apc.config.settings.server-0.0.1-SNAPSHOT.jar
      
      
               org.hibernate.dialect.PostgreSQLDialect: update
      
      
               hibernate.session_factory_name: persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
               hibernate.cache.region_prefix: persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
               hibernate.hbm2ddl.auto: update
      
      
               hibernate.bytecode.use_reflection_optimizer: false
      
      
               hibernate.show_sql: false
      
      
               hibernate.bytecode.provider: javassist
      
      
               hibernate.connection.release_mode: auto]
      
      
       13:19:49,637 DEBUG [Ejb3Configuration] Detect class: true; detect hbm: true
      
      
       13:19:49,637 DEBUG [Ejb3Configuration] Detect class: true; detect hbm: true
      
      
       13:19:49,637 DEBUG [AbstractJarVisitor] Searching mapped entities in jar/par: vfszip:/opt/jboss-5.1.0.GA/server/default/deploy/ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar/
      
      
       13:19:49,637 WARN  [Ejb3Configuration] Persistence provider caller does not implement the EJB3 spec correctly. PersistenceUnitInfo.getNewTempClassLoader() is null.
      
      
       13:19:49,638 DEBUG [AnnotationConfiguration] Execute first pass mapping processing
      
      
       13:19:49,638 DEBUG [AnnotationConfiguration] Process hbm files
      
      
       13:19:49,638 DEBUG [AnnotationConfiguration] Process annotated classes
      
      
       13:19:49,638 DEBUG [AnnotationConfiguration] processing fk mappings (*ToOne and JoinedSubclass)
      
      
       13:19:49,638 DEBUG [Configuration] processing extends queue
      
      
       13:19:49,638 DEBUG [Configuration] processing collection mappings
      
      
       13:19:49,638 DEBUG [Configuration] processing native query and ResultSetMapping mappings
      
      
       13:19:49,638 DEBUG [Configuration] processing association property references
      
      
       13:19:49,638 DEBUG [Configuration] processing foreign key constraints
      
      
       13:19:49,642 DEBUG [NamingHelper] No JNDI name configured for binding Ejb3Configuration
      
      
       13:19:49,643 DEBUG [HibernateSearchEventListenerRegister] Search not present in classpath, ignoring event listener registration.
      
      
       13:19:49,643 INFO  [HibernateSearchEventListenerRegister] Unable to find org.hibernate.search.event.FullTextIndexEventListener on the classpath. Hibernate Search is not enabled.
      
      
       13:19:49,644 DEBUG [Configuration] Preparing to build session factory with filters : {}
      
      
       13:19:49,644 DEBUG [AnnotationConfiguration] Execute first pass mapping processing
      
      
       13:19:49,644 DEBUG [AnnotationConfiguration] Process hbm files
      
      
       13:19:49,644 DEBUG [AnnotationConfiguration] Process annotated classes
      
      
       13:19:49,644 DEBUG [AnnotationConfiguration] processing fk mappings (*ToOne and JoinedSubclass)
      
      
       13:19:49,644 DEBUG [Configuration] processing extends queue
      
      
       13:19:49,644 DEBUG [Configuration] processing collection mappings
      
      
       13:19:49,644 DEBUG [Configuration] processing native query and ResultSetMapping mappings
      
      
       13:19:49,644 DEBUG [Configuration] processing association property references
      
      
       13:19:49,644 DEBUG [Configuration] processing foreign key constraints
      
      
       13:19:49,644 INFO  [ConnectionProviderFactory] Initializing connection provider: org.hibernate.ejb.connection.InjectedDataSourceConnectionProvider
      
      
       13:19:49,645 INFO  [InjectedDataSourceConnectionProvider] Using provided datasource
      
      
       13:19:49,645 INFO  [SettingsFactory] RDBMS: PostgreSQL, version: 8.4.2
      
      
       13:19:49,645 INFO  [SettingsFactory] JDBC driver: PostgreSQL Native Driver, version: PostgreSQL 8.1 JDBC3 with SSL (build 407)
      
      
       13:19:49,645 INFO  [Dialect] Using dialect: org.hibernate.dialect.PostgreSQLDialect
      
      
       13:19:49,645 INFO  [SettingsFactory] Automatic flush during beforeCompletion(): disabled
      
      
       13:19:49,645 INFO  [SettingsFactory] Automatic session close at end of transaction: disabled
      
      
       13:19:49,645 INFO  [SettingsFactory] JDBC batch size: 15
      
      
       13:19:49,645 INFO  [SettingsFactory] JDBC batch updates for versioned data: disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Scrollable result sets: enabled
      
      
       13:19:49,646 DEBUG [SettingsFactory] Wrap result sets: disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] JDBC3 getGeneratedKeys(): disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Connection release mode: auto
      
      
       13:19:49,646 INFO  [SettingsFactory] Maximum outer join fetch depth: 2
      
      
       13:19:49,646 INFO  [SettingsFactory] Default batch fetch size: 1
      
      
       13:19:49,646 INFO  [SettingsFactory] Generate SQL with comments: disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Order SQL updates by primary key: disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Order SQL inserts for batching: disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
      
      
       13:19:49,646 INFO  [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
      
      
       13:19:49,646 INFO  [SettingsFactory] Query language substitutions: {}
      
      
       13:19:49,646 INFO  [SettingsFactory] JPA-QL strict compliance: enabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Second-level cache: enabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Query cache: disabled
      
      
       13:19:49,646 INFO  [SettingsFactory] Cache region factory : org.hibernate.cache.impl.bridge.RegionFactoryCacheProviderBridge
      
      
       13:19:49,646 INFO  [RegionFactoryCacheProviderBridge] Cache provider: org.hibernate.cache.HashtableCacheProvider
      
      
       13:19:49,647 INFO  [SettingsFactory] Optimize cache for minimal puts: disabled
      
      
       13:19:49,647 INFO  [SettingsFactory] Cache region prefix: persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
       13:19:49,647 INFO  [SettingsFactory] Structured second-level cache entries: disabled
      
      
       13:19:49,647 INFO  [SettingsFactory] Statistics: disabled
      
      
       13:19:49,647 INFO  [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
      
      
       13:19:49,647 INFO  [SettingsFactory] Default entity-mode: pojo
      
      
       13:19:49,647 INFO  [SettingsFactory] Named query checking : enabled
      
      
       13:19:49,651 INFO  [SessionFactoryImpl] building session factory
      
      
       13:19:49,651 DEBUG [SessionFactoryImpl] Session factory constructed with filter configurations : {}
      
      
       13:19:49,651 DEBUG [SessionFactoryImpl] instantiating session factory with properties: {}
      
      
       13:19:49,651 DEBUG [SessionFactoryObjectFactory] registered: ff80808127aec5680127aecc7e93000b (persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server)
      
      
       13:19:49,651 INFO  [SessionFactoryObjectFactory] Factory name: persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
       13:19:49,651 INFO  [NamingHelper] JNDI InitialContext properties:{java.naming.factory.initial=org.jnp.interfaces.NamingContextFactory, java.naming.factory.url.pkgs=org.jboss.naming:org.jnp.interfaces}
      
      
       13:19:49,652 DEBUG [SessionFactoryImpl] Returning a Reference to the SessionFactory
      
      
       13:19:49,652 DEBUG [NamingHelper] Bound name: persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
       13:19:49,652 INFO  [SessionFactoryObjectFactory] Bound factory to JNDI name: persistence.unit:unitName=ISXO_Core.ear/com.apc.config.settings.server-0.0.1-SNAPSHOT.jar#settingDataSource-server
      
      
       13:19:49,652 WARN  [SessionFactoryObjectFactory] InitialContext did not implement EventContext
      
      
       13:19:49,652 DEBUG [SessionFactoryImpl] instantiated session factory
      
      
       13:19:49,652 INFO  [SchemaUpdate] Running hbm2ddl schema update
      
      
       13:19:49,652 INFO  [SchemaUpdate] fetching database metadata
      
      
       13:19:49,655 INFO  [SchemaUpdate] updating schema
      
      
       13:19:49,655 DEBUG [AnnotationConfiguration] Execute first pass mapping processing
      
      
       13:19:49,655 DEBUG [AnnotationConfiguration] Process hbm files
      
      
       13:19:49,655 DEBUG [AnnotationConfiguration] Process annotated classes
      
      
       13:19:49,655 DEBUG [AnnotationConfiguration] processing fk mappings (*ToOne and JoinedSubclass)
      
      
       13:19:49,655 DEBUG [Configuration] processing extends queue
      
      
       13:19:49,655 DEBUG [Configuration] processing collection mappings
      
      
       13:19:49,655 DEBUG [Configuration] processing native query and ResultSetMapping mappings
      
      
       13:19:49,655 DEBUG [Configuration] processing association property references
      
      
       13:19:49,656 DEBUG [Configuration] processing foreign key constraints
      
      
       13:19:49,656 INFO  [SchemaUpdate] schema update complete
      

       

      Thanks

      /Flemming

        • 1. Re: hbm file is not picked up by the scanner
          jaikiran

          Flemming Harms wrote:

           

          I'm having a bit of a puzzle with JBoss AS 5.1.0.GA and Hibernate. I have 3 jar files with contains persistence.xml file and hbm files located in META-INF\hibernatemapping and all packed in the root of the ear file, but there is one jar file where the hbm file is not scanned and I can't figure out what is wrong or how to investigate this.

           

          I have two other jar files which is working fine and the hbm files is detected and loaded.

           

          I don't know how the other 2 jars files were able to load the .hbm.xml files. But as per JPA spec only META-INF/orm.xml is scanned for entity class mapping.

          • 2. Re: hbm file is not picked up by the scanner
            fharms

            then I'm a bit confused because I thought the EJB3 deployer will search the archive for any .hbm.xml

             

            http://www.jboss.org/file-access/default/members/jbossejb3/freezone/docs/tutorial/1.0.7/html_single/index.html#Hibernate_Session_In_EJB3

             

            But what will then be the proper way to scan for hbm files so it managed by the EntityManager?

             

            Thanks

             

            /Flemming

            • 3. Re: hbm file is not picked up by the scanner
              fharms

              I have been doing some more investigation on this and find out a different where the hbm files is loaded and those are not. I have been looking into the source code for Jboss and one different I have noticed was when hbm files is not loaded InputStream result = getHandler().openStream() in VirtualFile.java return a ByteArrayInputStream and that makes getNextJarEntry() in InputStreamZippedJarVisitor return null.

              For the jar files that are working I found out InputStream result = getHandler().openStream() return a FileInputStream and in this case getNextJarEntry() return a entry.

              I haven't figured out why in one case it return a ByteArrayInputStream and in other cases it retur a FileInputStream. It might be a wild goose chase, but I'm bit lost because when I read the documentation and few blog entries I understand it as the hibernate entity managers will add all hbm files to the persistence unit by default

              http://docs.jboss.org/hibernate/stable/entitymanager/reference/en/html/configuration.html#setup-configuration-packaging

              • 4. Re: hbm file is not picked up by the scanner
                fharms

                I found a work around for this issue by simple add the <mapping-file>META-INF/hibernatemappings/Setting.hbm.xml</mapping-file> to the persistence.xml file. It's bit trivial if you have a lot of hbm files but it's better then nothing

                I still not completely understand why in some cases the scanner is loading the hbm files and in other cases it's not. I did create a small test application where it work as I expected and the hbm files is added to the persistence unit.

                 

                /Flemming