2 Replies Latest reply on Aug 6, 2007 11:02 AM by jfrankman

    Quartz Classpath issues. How to configure.

    jfrankman Novice

      I am trying to use the quartz scheduler that comes with JBoss. I have created a simple job that logs a message every few minutes. Now that I have this working, I want to call a job that requires Hibernate and Java Persistence. When I do this I get errors because the persistence.xml file is not found in META-INF folder. I beleive this is a class path issue. Here is the error I am getting:

      12:36:00,034 INFO [Ejb3Configuration] Could not find any META-INF/persistence.xml file in the classpath
      12:36:00,034 WARN [UserSuppliedConnectionProvider] No connection properties specified - the user must supply JDBC connections
      12:36:00,034 ERROR [JobRunShell] Job default.job.0.1186166057839 threw an unhandled Exception:
      javax.ejb.EJBTransactionRolledbackException: javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
       at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:93)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:130)
       at org.jboss.aspects.tx.TxInterceptor$Required.invoke(TxInterceptor.java:195)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.stateless.StatelessInstanceInterceptor.invoke(StatelessInstanceInterceptor.java:62)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.mdb.MessagingContainer.localInvoke(MessagingContainer.java:245)
       at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
       at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
       at $Proxy133.execute(Unknown Source)
       at org.jboss.resource.adapter.quartz.inflow.QuartzJob.execute(QuartzJob.java:57)
       at org.quartz.core.JobRunShell.run(JobRunShell.java:203)
       at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
      Caused by: javax.persistence.PersistenceException: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:698)
       at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:121)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:51)
       at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:33)
       at com.idfbins.nexus.batch.GISDataBatch.init(GISDataBatch.java:42)
       at com.idfbins.nexus.batch.GISDataBatch.assignLocationsCoordinates(GISDataBatch.java:55)
       at com.idfbins.nexus.batch.ExecuteGISBatch.execute(ExecuteGISBatch.java:34)
       at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
       at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:585)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:112)
       at org.jboss.ejb3.interceptor.InvocationContextImpl.proceed(InvocationContextImpl.java:166)
       at org.jboss.ejb3.interceptor.EJB3InterceptorsInterceptor.invoke(EJB3InterceptorsInterceptor.java:63)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.entity.TransactionScopedEntityManagerInterceptor.invoke(TransactionScopedEntityManagerInterceptor.java:54)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.ejb3.AllowedOperationsInterceptor.invoke(AllowedOperationsInterceptor.java:46)
       at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
       at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
       ... 11 more
      Caused by: org.hibernate.HibernateException: Hibernate Dialect must be explicitly set
       at org.hibernate.dialect.DialectFactory.determineDialect(DialectFactory.java:57)
       at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:39)
       at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:409)
       at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
       at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:1933)
       at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1216)
       at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:691)
       ... 30 more
      


      Here is my setting the the ejb-jar.xml:

      <message-driven>
       <ejb-name>GISBatch</ejb-name>
       <ejb-class>com.idfbins.nexus.batch.ExecuteGISBatch</ejb-class>
       <messaging-type>org.quartz.Job</messaging-type>
       <transaction-type>Container</transaction-type>
       <activation-config>
       <activation-config-property>
       <activation-config-property-name>
       cronTrigger
       </activation-config-property-name>
       <activation-config-property-value>
       <![CDATA[0 */2 * * * ?]]>
       </activation-config-property-value>
       </activation-config-property>
       </activation-config>
       </message-driven>


      Here is my JBoss.xml:

      <?xml version="1.0" encoding="UTF-8"?>
      <jboss>
       <enterprise-beans>
       <message-driven>
       <ejb-name>QuartzTst2</ejb-name>
       <resource-adapter-name>quartz-ra.rar</resource-adapter-name>
       </message-driven>
       <message-driven>
       <ejb-name>GISBatch</ejb-name>
       <resource-adapter-name>quartz-ra.rar</resource-adapter-name>
       </message-driven>
      
       </enterprise-beans>
      </jboss>
      



      Here is the class that gets scheduled. It is located inside and EAR deployed on JBoss:
      package com.idfbins.nexus.batch;
      
      import javax.ejb.EJBException;
      import javax.ejb.MessageDrivenContext;
      import javax.jms.Message;
      
      import org.jboss.logging.Logger;
      import org.quartz.JobExecutionContext;
      import org.quartz.JobExecutionException;
      
      public class ExecuteGISBatch {
      
       /**
       * @param args
       */
       /*
       public static void main(String[] args) {
       // TODO Auto-generated method stub
       GISDataBatch batch = new GISDataBatch();
       batch.assignLocationsCoordinates();
       }
       */
      
       private static final Logger log = Logger.getLogger(QuartzTst2.class);
      
       public void execute(JobExecutionContext jobExecutionContext)
       throws JobExecutionException {
       log.info("Executing GIS Batch");
       log.info("class path="+System.getProperty(
       "java.class.path"
       ));
      
       GISDataBatch batch = new GISDataBatch();
       batch.assignLocationsCoordinates();
       }
      
       /**
       * *
       *
       * @see javax.ejb.MessageDrivenBean#ejbRemove() *
       * @throws EJBException
       */
       public void ejbRemove() throws EJBException {
       }
      
       /**
       * *
       *
       * @see javax.ejb.MessageDrivenBean#setMessageDrivenContext(javax.ejb.MessageDrivenContext) *
       * @param context *
       * @throws EJBException
       */
       public void setMessageDrivenContext(MessageDrivenContext context)
       throws EJBException {
       }
      
       /**
       * *
       *
       * @see javax.jms.MessageListener#onMessage(javax.jms.Message) *
       * @param message
       */
       public void onMessage(Message message) {
       }
      
       public void ejbCreate() {
       log.info("GIS Batch job created");
       }
      
      }


      I have read that if I set the Quartz property: useClassLoaderOfInitializer to true then it will use the JBoss class loader and everything should be on the classpath. If this is correct, I just need to know where to update or create the quartz.properties file. If I am incorrect I need to find a way to make sure that when the job is run that everything in my EAR is in the classpath. What is the best way to do this?



        • 1. Re: Quartz Classpath issues. How to configure.
          Elias Ross Master

          Not sure I can immediately help, but from what I see the code is reaching your class... It also feels like Hibernate sees your persistence.xml but perhaps you are missing something there.

          You should be able to see what Thread.currentThread().contextClassLoader() is set to. You should also be able to "find" persistence.xml yourself using a ClassLoader.getResources("META-INF/persistence.xml") call.

          • 2. Re: Quartz Classpath issues. How to configure.
            jfrankman Novice

            I don't think hibernate is seeing the persistence.xml file because I get the following:

            08:56:00,017 INFO [QuartzTst2] class path=C:\dev\jdk\5.0/lib/tools.jar;C:\dev\jboss-4.0.5.ejb3/bin/run.jar
            08:56:00,017 INFO [QuartzTst2] Class loader:org.jboss.mx.loading.UnifiedClassLoader3@bb0257{ url=file:/C:/dev/jboss-4.0.5.ejb3/server/default/tmp/deploy/tmp20982quartz-ra.rar ,addedOrder=42}
            08:56:00,033 INFO [Ejb3Configuration] Could not find any META-INF/persistence.xml file in the classpath
            08:56:00,033 WARN [UserSuppliedConnectionProvider] No connection properties specified - the user must supply JDBC connections


            It says it cannot find persistence.xml in the classpath. Also notice that I logged the class path and the classloader. What I don't understand is how it can find my class, but not the persistence.xml as they are in the same directory. This is really getting frustrating. All I want to do is schedule a job to run on a regular basis.