4 Replies Latest reply on Dec 11, 2008 11:04 AM by Jim Marks

    Hibernate MappingException "Unknown entity" with only one hb

    Jim Marks Newbie

      I am constructing a proof of concept for my organization as we plan out the new structure for a web-based application. While I have a fair bit of Java experience and a fair bit of web-based application experience, this is my first attempt at a properly structured, Java-based, web-based application. It is also the first of these for my organization (previous version is ASP/.Net). The learning curve has been steep, but I am nearly there. One (apparent) hurdle remains. I will try to describe my environment in as much detail as possible.

      JBoss 4.2.3.GA
      Hibernate 3 (whatever is bundled into the above JBoss)
      Spring 2.5.5

      Because our application will eventually be quite substantial and complex, I have been attempting to use a .har file, which includes the hibernate-service.xml as well as the *.hbm.xml files, rather than using a hibernate.cgf.xml and then explicitly listing all the .hbm.xml files in the bean definition within the applicationContext.xml file. Since my ant build script can literally say *.hbm.xml but I (and all the other developers) would have to remember to add a new line to the bean definition every time we added a class with the other approach.

      When I build my .ear file, it includes the .har file (which includes the hibernate-service.xml and the *.hbm.xml files) and the .war file which contains the application itself. There is also a META-INF folder which contains a jboss-app.xml (describing the .har file) and an application.xml file (describing the .war file).

      When I deploy my .ear file, I can watch JBoss deploying Hibernate (from the .har I assume?), and it throws an org.hibernate.MappingException "Unknown Entity" on the one and only class from the one and only .hbm.xml file during this deployment. The .ear continues to deploy and my web-app is up and running. Obviously if I attempt to access it, I get a much more serious error, because the application attempts to make use of a Hibernate binding that now doesn't exist.

      The hbm.xml file in question is very simple and appears to be syntactically correct. I have to conclude that JBoss is finding this .hbm.xml file or how else would it be able to throw this kind of exception at deployment rather than runtime?

      I don't know what additional information details to provide to illuminate for someone more experienced than myself to see what the problem may be.

      Any help would be greatly appreciated, thanks.

        • 1. Re: Hibernate MappingException
          jaikiran pai Master

          Please post the console logs along with the entire exception stacktrace.

          While posting logs or xml content or code, please remember to wrap it in a code block by using the Code button in the message editor window. Also please hit the Preview button before posting, to ensure your post is correctly formatted.

          • 2. Re: Hibernate MappingException
            Jim Marks Newbie

            sorry, working across two different machines. not "unknown entity" but "entity class not found".

            here's everything from the deployment of the ear.

            07:24:53,734 INFO [EARDeployer] Init J2EE application: file:/D:/Profiles/awxcm/jboss-4.2.3.GA/server/default/deploy/NextGenRM_Demo.ear
            07:24:55,421 INFO [Environment] Hibernate 3.2.4.sp1
            07:24:55,453 INFO [Environment] hibernate.properties not found
            07:24:55,453 INFO [Environment] Bytecode provider name : javassist
            07:24:55,453 INFO [Environment] using JDK 1.4 java.sql.Timestamp handling
            07:24:55,515 INFO [Configuration] Searching for mapping documents in jar: NextGenRMDemo.har
            07:24:55,515 INFO [Configuration] Found mapping document in jar: Date.hbm.xml
            07:24:55,625 INFO [HbmBinder] Mapping class: com.agfa.healthcare.resultsmanagement.domain.Date -> dates
            07:24:55,687 INFO [NamingHelper] JNDI InitialContext properties:{}
            07:24:55,703 INFO [DatasourceConnectionProvider] Using datasource: java:/NextGenRMDemoDS
            07:24:55,703 INFO [SettingsFactory] RDBMS: HSQL Database Engine, version: 1.8.0
            07:24:55,703 INFO [SettingsFactory] JDBC driver: HSQL Database Engine Driver, version: 1.8.0
            07:24:55,734 INFO [Dialect] Using dialect: org.hibernate.dialect.HSQLDialect
            07:24:55,734 INFO [TransactionFactoryFactory] Transaction strategy: org.hibernate.transaction.JTATransactionFactory
            07:24:55,734 INFO [NamingHelper] JNDI InitialContext properties:{}
            07:24:55,734 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
            07:24:55,734 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
            07:24:55,734 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: org.hibernate.transaction.JBossTransactionManagerLookup
            07:24:55,734 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
            07:24:55,734 INFO [SettingsFactory] Automatic flush during beforeCompletion(): enabled
            07:24:55,734 INFO [SettingsFactory] Automatic session close at end of transaction: enabled
            07:24:55,734 INFO [SettingsFactory] JDBC batch size: 15
            07:24:55,734 INFO [SettingsFactory] JDBC batch updates for versioned data: disabled
            07:24:55,734 INFO [SettingsFactory] Scrollable result sets: enabled
            07:24:55,734 INFO [SettingsFactory] JDBC3 getGeneratedKeys(): enabled
            07:24:55,734 INFO [SettingsFactory] Connection release mode: after_statement
            07:24:55,734 INFO [SettingsFactory] Default batch fetch size: 1
            07:24:55,734 INFO [SettingsFactory] Generate SQL with comments: disabled
            07:24:55,734 INFO [SettingsFactory] Order SQL updates by primary key: disabled
            07:24:55,734 INFO [SettingsFactory] Order SQL inserts for batching: disabled
            07:24:55,734 INFO [SettingsFactory] Query translator: org.hibernate.hql.ast.ASTQueryTranslatorFactory
            07:24:55,734 INFO [ASTQueryTranslatorFactory] Using ASTQueryTranslatorFactory
            07:24:55,734 INFO [SettingsFactory] Query language substitutions: {}
            07:24:55,734 INFO [SettingsFactory] JPA-QL strict compliance: disabled
            07:24:55,734 INFO [SettingsFactory] Second-level cache: enabled
            07:24:55,734 INFO [SettingsFactory] Query cache: disabled
            07:24:55,734 INFO [SettingsFactory] Cache provider: org.hibernate.cache.HashtableCacheProvider
            07:24:55,734 INFO [SettingsFactory] Optimize cache for minimal puts: disabled
            07:24:55,734 INFO [SettingsFactory] Structured second-level cache entries: disabled
            07:24:55,750 INFO [SettingsFactory] Echoing all SQL to stdout
            07:24:55,750 INFO [SettingsFactory] Statistics: disabled
            07:24:55,750 INFO [SettingsFactory] Deleted entity synthetic identifier rollback: disabled
            07:24:55,750 INFO [SettingsFactory] Default entity-mode: pojo
            07:24:55,750 INFO [SettingsFactory] Named query checking : enabled
            07:24:55,812 INFO [SessionFactoryImpl] building session factory
            07:24:55,875 WARN [ServiceController] Problem starting service jboss.har:service=Hibernate
            org.hibernate.MappingException: entity class not found: com.agfa.healthcare.resultsmanagement.domain.Date
             at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:99)
             at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
             at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
             at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
             at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
             at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
             at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
             at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
             at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
             at org.jboss.hibernate.jmx.Hibernate.buildSessionFactory(Hibernate.java:231)
             at org.jboss.hibernate.jmx.Hibernate.startService(Hibernate.java:155)
             at org.jboss.system.ServiceMBeanSupport.jbossInternalStart(ServiceMBeanSupport.java:289)
             at org.jboss.system.ServiceMBeanSupport.jbossInternalLifecycle(ServiceMBeanSupport.java:245)
             at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
             at org.jboss.system.ServiceController$ServiceProxy.invoke(ServiceController.java:978)
             at $Proxy0.start(Unknown Source)
             at org.jboss.system.ServiceController.start(ServiceController.java:417)
             at sun.reflect.GeneratedMethodAccessor9.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:86)
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
             at $Proxy4.start(Unknown Source)
             at org.jboss.deployment.SARDeployer.start(SARDeployer.java:304)
             at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1025)
             at org.jboss.deployment.MainDeployer.start(MainDeployer.java:1015)
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:819)
             at org.jboss.deployment.MainDeployer.deploy(MainDeployer.java:782)
             at sun.reflect.GeneratedMethodAccessor25.invoke(Unknown Source)
             at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
             at java.lang.reflect.Method.invoke(Method.java:597)
             at org.jboss.mx.interceptor.ReflectedDispatcher.invoke(ReflectedDispatcher.java:155)
             at org.jboss.mx.server.Invocation.dispatch(Invocation.java:94)
             at org.jboss.mx.interceptor.AbstractInterceptor.invoke(AbstractInterceptor.java:133)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
             at org.jboss.mx.interceptor.ModelMBeanOperationInterceptor.invoke(ModelMBeanOperationInterceptor.java:142)
             at org.jboss.mx.server.Invocation.invoke(Invocation.java:88)
             at org.jboss.mx.server.AbstractMBeanInvoker.invoke(AbstractMBeanInvoker.java:264)
             at org.jboss.mx.server.MBeanServerImpl.invoke(MBeanServerImpl.java:659)
             at org.jboss.mx.util.MBeanProxyExt.invoke(MBeanProxyExt.java:210)
             at $Proxy9.deploy(Unknown Source)
             at org.jboss.deployment.scanner.URLDeploymentScanner.deploy(URLDeploymentScanner.java:421)
             at org.jboss.deployment.scanner.URLDeploymentScanner.scan(URLDeploymentScanner.java:634)
             at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.doScan(AbstractDeploymentScanner.java:263)
             at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.loop(AbstractDeploymentScanner.java:274)
             at org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread.run(AbstractDeploymentScanner.java:225)
            Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: com.agfa.healthcare.resultsmanagement.domain.Date
             at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:521)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:415)
             at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
             at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
             at java.lang.Class.forName0(Native Method)
             at java.lang.Class.forName(Class.java:169)
             at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
             at org.hibernate.mapping.PersistentClass.getMappedClass(PersistentClass.java:96)
             ... 56 more
            07:24:55,890 INFO [TomcatDeployer] deploy, ctxPath=/NextGenRM_Demo, warUrl=.../tmp/deploy/tmp5375NextGenRM_Demo.ear-contents/NextGenRM_Demo-exp.war/
            07:24:56,281 INFO [[/NextGenRM_Demo]] Initializing Spring root WebApplicationContext
            07:24:56,281 INFO [ContextLoader] Root WebApplicationContext: initialization started
            07:24:56,328 INFO [XmlWebApplicationContext] Refreshing org.springframework.web.context.support.XmlWebApplicationContext@24d3a: display name [Root WebApplicationContext]; startup date [Thu Dec 11 07:24:56 CST 2008]; root of context hierarchy
            07:24:56,406 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/applicationContext.xml]
            07:24:56,468 INFO [XmlWebApplicationContext] Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@24d3a]: org.springframework.beans.factory.support.DefaultListableBeanFactory@b458fd
            07:24:56,500 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@b458fd: defining beans []; root of factory hierarchy
            07:24:56,500 INFO [ContextLoader] Root WebApplicationContext: initialization completed in 219 ms
            07:24:56,546 INFO [[/NextGenRM_Demo]] Initializing Spring FrameworkServlet 'nextgenrm_demo'
            07:24:56,546 INFO [DispatcherServlet] FrameworkServlet 'nextgenrm_demo': initialization started
            07:24:56,546 INFO [XmlWebApplicationContext] Refreshing org.springframework.web.context.support.XmlWebApplicationContext@134329b: display name [WebApplicationContext for namespace 'nextgenrm_demo-servlet']; startup date [Thu Dec 11 07:24:56 CST 2008]; parent: org.springframework.web.context.support.XmlWebApplicationContext@24d3a
            07:24:56,546 INFO [XmlBeanDefinitionReader] Loading XML bean definitions from ServletContext resource [/WEB-INF/nextgenrm_demo-servlet.xml]
            07:24:56,578 INFO [XmlWebApplicationContext] Bean factory for application context [org.springframework.web.context.support.XmlWebApplicationContext@134329b]: org.springframework.beans.factory.support.DefaultListableBeanFactory@1a1732d
            07:24:56,625 INFO [DefaultListableBeanFactory] Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1a1732d: defining beans [messageSource,/dateList.htm,/modifyDays.htm,dateDao,dateManager,viewResolver]; parent: org.springframework.beans.factory.support.DefaultListableBeanFactory@b458fd
            07:24:56,765 INFO [DispatcherServlet] FrameworkServlet 'nextgenrm_demo': initialization completed in 219 ms
            07:24:56,781 INFO [EARDeployer] Started J2EE application: file:/D:/Profiles/awxcm/jboss-4.2.3.GA/server/default/deploy/NextGenRM_Demo.ear
            
            
            


            • 3. Re: Hibernate MappingException
              jaikiran pai Master

               

              class not found: com.agfa.healthcare.resultsmanagement.domain.Date

              Where exactly is this class present in your packaging? Is it part of the har or is it bundled in a separate jar? If its in a separate jar, where in the EAR is the jar placed?

              • 4. Re: Hibernate MappingException
                Jim Marks Newbie

                 

                "jaikiran" wrote:
                Where exactly is this class present in your packaging? Is it part of the har or is it bundled in a separate jar? If its in a separate jar, where in the EAR is the jar placed?


                Thank you for the reply. I eventually figured this part out. I am now building an ear that contains a jar, a har and a war. The har is the same as before. The jar contains all the non-web-specific classes for my application. The war contains the web-specific classes as well as the servlet definitions. I am no longer getting the above error with regards to being unable to map the Date class. (I'm now getting a different error related to servlets finding things which live in the jar instead of the war, but that's a separate forum.)


                One line in the console log still confuses me:

                09:56:29,373 INFO [SessionFactoryImpl] building session factory
                09:56:29,561 INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured
                09:56:29,561 INFO [NamingHelper] JNDI InitialContext properties:{}
                09:56:29,561 INFO [Hibernate] SessionFactory successfully built and bound into JNDI [java:/hibernate/NextGenRMDemoSessionFactory]
                


                What JNDI is the SessionFactoryObjectFactory not finding?

                Jboss-web.xml looks like this:

                <?xml version="1.0" encoding="UTF-8"?>
                
                <jboss-web>
                
                 <resource-ref>
                 <res-ref-name>jdbc/NextGenRMDemoDS</res-ref-name>
                 <jndi-name>java:/NextGenRMDemoDS</jndi-name>
                 </resource-ref>
                
                 <resource-ref>
                 <res-ref-name>hibernate/NextGenRMDemoSessionFactory</res-ref-name>
                 <jndi-name>java:/hibernate/NextGenRMDemoSessionFactory</jndi-name>
                 </resource-ref>
                
                </jboss-web>