5 Replies Latest reply on Apr 6, 2005 4:35 PM by cglommen

    Hibernate as MBEAN YET "hibernate.cfg.xml not found' ERROR

    gunzip

      I making a Staless Session EJB connect with Hibernate and do some simple stuff with postgres, it worked for a while
      but then all of the sudden everything stops working

      my directory structure is
      ejbhiernate.ear(FULL ENTERPRISE APPLICATION)
      EAR
      META-INF
      application.xml
      jboss-app.xml
      jboss-service.xml
      mappings
      User.hbm.xml

      ejbhibernate.jar(EJB for accessing hibernate and then postgres)
      client.war(web application to see the EJB results)
      hibermap.sar(mappings and xmls)

      JAR(EJB folder, will be created an JAR out of this and then go in ear)
      META-INF
      ejb-jar.xml
      jboss.xml
      org.jboss.ejbhibernate
      classes EJB(Bean,Remote,etc)
      SAR(Hibernate folder, will be created an SAR then go to EAR folder
      META-INF
      jboss-service.xml(it is already on EAR, DOES IT NEED TO GO HERE TOO?)
      mappings(SAME THING HERE, WICH ONE SHOULD BE REMOVED?)
      User.hbml.xml
      org.jboss.ejbhibernate(the PERSISTENT DATABASE classes, but I think they useless here, ANYONE knows if they should be go here also?-beside on war/web-inf/classes?)
      src(compiled classes from ANT of EJB and Servlets of the war)
      war
      WEB-INF
      Classes
      org.jboss.ejbhibernate
      EJBHomeInteface
      ServletForStartingEverything
      + a bunch of classes from ejb that came along with ant copied from src

      Jboss-web.xml
      web.xml

      How do i OPTIMIZE this situation.????
      Jboss keep alerting that hibernate.cfg.xml is not found yet you dont
      need it when you using hibernate as mbean, whats Im doing wrong?
      I have jboss-service.xml(in both SAR and EAR) as


      jboss.jca:service=SARDeployer
      jboss.jca:service=LocalTxCM,name=PostgresDS
      <!-- Make it deploy ONLY after DataSource had been started -->
      mappings/User.hbm.xml
      java:/hibernate/HibernateFactory
      java:/PostgresDS
      net.sf.hibernate.dialect.PostgreSQLDialect
      net.sf.hibernate.transaction.JTATransactionFactory
      net.sf.hibernate.transaction.JBossTransactionManagerLookup
      false
      false
      UserTransaction



      It deploys PERFECTLY, jndi is bound, mappings ok, but then when the SERVLET OR EJB tries to connect with hibernate with
      sessionFactory = new Configuration().configure().buildSessionFactory();
      it gives 'hibernate.cfg.xml' not found, where is the ERROR?
      Any idea?

        • 1. Re: Hibernate as MBEAN YET
          gunzip

          BTW
          its JBOSS 3.2.3
          Hibernate2.1
          Red Hat 9
          And ANT includes all that jars from hibernate and j2ee

          • 2. Re: Hibernate as MBEAN YET
            starksm64
            • 3. Re: Hibernate as MBEAN YET
              gunzip

              Ive already followed that, as I said the EAR DEPLOYS alright look:

              14:16:37,423 INFO [MainDeployer] Starting deployment of package: file:/usr/local/src/jboss-3.2.3/server/default/deploy/ejbhibernate.ear
              14:16:37,425 INFO [EARDeployer] Init J2EE application: file:/usr/local/src/jboss-3.2.3/server/default/deploy/ejbhibernate.ear
              14:16:39,211 INFO [EjbModule] Deploying test/EJBHibernate
              14:16:39,395 INFO [HibernateServiceMBean] starting service at JNDI name: java:/hibernate/HibernateFactory
              14:16:39,396 INFO [HibernateServiceMBean] service properties: {hibernate.session_factory_name=java:/hibernate/HibernateFactory, hibernate.transaction.manager_lookup_class=net.sf.hibernate.transaction.JBossTransactionManagerLookup, hibernate.dialect=net.sf.hibernate.dialect.PostgreSQLDialect, hibernate.show_sql=false, hibernate.use_outer_join=false, hibernate.transaction.factory_class=net.sf.hibernate.transaction.JTATransactionFactory, hibernate.connection.datasource=java:/PostgresDS, jta.UserTransaction=UserTransaction}
              14:16:39,397 INFO [Configuration] Mapping resource: mappings/User.hbm.xml
              14:16:39,695 INFO [Binder] Mapping class: org.jboss.ejbhibernate.User -> users
              14:16:39,698 INFO [Configuration] processing one-to-many association mappings
              14:16:39,703 INFO [Configuration] processing one-to-one association property references
              14:16:39,703 INFO [Configuration] processing foreign key constraints
              14:16:39,706 INFO [Dialect] Using dialect: net.sf.hibernate.dialect.PostgreSQLDialect
              14:16:39,707 INFO [SettingsFactory] Use outer join fetching: false
              14:16:39,708 INFO [NamingHelper] JNDI InitialContext properties:{}
              14:16:40,131 INFO [DatasourceConnectionProvider] Using datasource: java:/PostgresDS
              14:16:40,132 INFO [TransactionFactoryFactory] Transaction strategy: net.sf.hibernate.transaction.JTATransactionFactory
              14:16:40,135 INFO [NamingHelper] JNDI InitialContext properties:{}
              14:16:40,167 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
              14:16:40,170 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
              14:16:40,171 INFO [NamingHelper] JNDI InitialContext properties:{}
              14:16:40,174 INFO [TransactionManagerLookupFactory] instantiating TransactionManagerLookup: net.sf.hibernate.transaction.JBossTransactionManagerLookup
              14:16:40,175 INFO [TransactionManagerLookupFactory] instantiated TransactionManagerLookup
              14:16:40,182 INFO [SettingsFactory] Use scrollable result sets: true
              14:16:40,182 INFO [SettingsFactory] Use JDBC3 getGeneratedKeys(): false
              14:16:40,183 INFO [SettingsFactory] Optimize cache for minimal puts: false
              14:16:40,183 INFO [SettingsFactory] Query language substitutions: {}
              14:16:40,183 INFO [SettingsFactory] cache provider: net.sf.ehcache.hibernate.Provider
              14:16:40,185 INFO [Configuration] instantiating and configuring caches
              14:16:40,185 INFO [SessionFactoryImpl] building session factory
              14:16:40,485 INFO [SessionFactoryObjectFactory] Factory name: java:/hibernate/HibernateFactory
              14:16:40,486 INFO [NamingHelper] JNDI InitialContext properties:{}
              14:16:40,488 INFO [SessionFactoryObjectFactory] Bound factory to JNDI name: java:/hibernate/HibernateFactory
              14:16:40,489 WARN [SessionFactoryObjectFactory] InitialContext did not implement EventContext
              14:16:40,490 INFO [NamingHelper] JNDI InitialContext properties:{}
              14:16:40,777 INFO [StatelessSessionInstancePool] Started jboss.j2ee:jndiName=ejb/test/EJBHibernate,plugin=pool,service=EJB
              14:16:40,778 INFO [StatelessSessionContainer] Started jboss.j2ee:jndiName=ejb/test/EJBHibernate,service=EJB
              14:16:40,779 INFO [EjbModule] Started jboss.j2ee:module=ejbhibernate.jar,service=EjbModule
              14:16:41,932 INFO [EJBDeployer] Deployed: file:/usr/local/src/jboss-3.2.3/server/default/tmp/deploy/tmp461ejbhibernate.ear-contents/ejbhibernate.jar
              14:16:43,275 INFO [EmbeddedTomcatService] deploy, ctxPath=/ejbhibernate, warUrl=file:/usr/local/src/jboss-3.2.3/server/default/tmp/deploy/tmp461ejbhibernate.ear-contents/client.war/
              14:16:43,739 INFO [Engine] SingleSignOnContextConfig[/ejbhibernate]: Added certificates -> request attribute Valve
              14:16:43,922 WARN [EmbeddedTomcatService] Unable to invoke setDelegate on class loader:org.jboss.web.tomcat.tc4.WebCtxLoader$ENCLoader@17c50b9
              14:16:43,923 INFO [Engine] StandardManager[/ejbhibernate]: Seeding random number generator class java.security.SecureRandom
              14:16:44,007 INFO [Engine] StandardManager[/ejbhibernate]: Seeding of random number generator has been completed
              14:16:44,010 INFO [Engine] StandardWrapper[/ejbhibernate:default]: Loading container servlet default
              14:16:44,066 INFO [Engine] StandardWrapper[/ejbhibernate:invoker]: Loading container servlet invoker
              14:16:44,942 INFO [EARDeployer] Started J2EE application: file:/usr/local/src/jboss-3.2.3/server/default/deploy/ejbhibernate.ear
              14:16:44,943 INFO [MainDeployer] Deployed package: file:/usr/local/src/jboss-3.2.3/server/default/deploy/ejbhibernate.ear

              But when I run the servelt that calls the EJB Session(Who calls Hibernate) I receive:
              pages and pages of errors, the hightlights are:(START)
              2004-04-05 14:20:06,756 DEBUG [org.apache.tomcat.util.threads.ThreadPool] Getting new thread data2004-04-05 14:20:07,528 INFO [org.jboss.security.plugins.JaasSecurityManagerService] Created securityMgr=org.jboss.security.plugins.JaasSecurityManager@645fd
              2004-04-05 14:20:07,533 INFO [org.jboss.security.plugins.JaasSecurityManagerService] setCachePolicy, c=org.jboss.util.TimedCachePolicy@125d568
              2004-04-05 14:20:07,534 INFO [org.jboss.security.plugins.JaasSecurityManagerService] Added LWebSec, org.jboss.security.plugins.SecurityDomainContext@ddcd98 to map
              (SNIP)
              *********************************************************
              2004-04-05 14:20:07,869 INFO [net.sf.hibernate.cfg.Configuration] configuring from resource: /hibernate.cfg.xml
              2004-04-05 14:20:07,870 INFO [net.sf.hibernate.cfg.Configuration] Configuration resource: /hibernate.cfg.xml
              2004-04-05 14:20:07,884 WARN [net.sf.hibernate.cfg.Configuration] /hibernate.cfg.xml not found
              2004-04-05 14:20:07,932 ERROR [org.jboss.ejb.plugins.LogInterceptor] Unexpected Error:
              java.lang.ExceptionInInitializerError
              at org.jboss.ejbhibernate.EjbHibernateBean.SayHello(EjbHibernateBean.java:31)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

              **********************************************
              at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:605)
              at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:677)
              at java.lang.Thread.run(Thread.java:534)
              14:20:08,065 ERROR [STDERR] java.rmi.ServerError: Unexpected Error; nested exception is:
              java.lang.NoClassDefFoundError
              14:20:08,070 ERROR [STDERR] at org.jboss.ejb.plugins.LogInterceptor.handleException(LogInterceptor.java:374)
              ********************************************
              at java.lang.Thread.run(Thread.java:534)
              Caused by: java.lang.RuntimeException: Exception building SessionFactory: /hibernate.cfg.xml not
              found
              at org.jboss.ejbhibernate.HibernateUtil.(HibernateUtil.java:14)
              ... 71 more
              Caused by: net.sf.hibernate.HibernateException: /hibernate.cfg.xml not found

              I using the HibernateUtil.class to TRY

              static {
              try {
              sessionFactory = new Configuration().configure().buildSessionFactory();
              } catch (HibernateException ex) {
              throw new RuntimeException("Exception building SessionFactory: " + ex.getMessage(), ex);
              }
              }
              And the configuration lines gives the error, maybe I SHOULD SET A PARAMETER on the function or on one of the XMLS??????????

              • 4. Re: Hibernate as MBEAN YET
                gunzip

                Btw, I solved the problem
                the hibernate example(first persistent class)
                SHOULNDT be used with jboss, specially the way
                the hibernateutil class starts, its wrong and will result in error

                • 5. Re: Hibernate as MBEAN YET
                  cglommen

                  I am having the same problem....PLEASE post your solution:)