title: Hibernate 4: How do I resolve a "An AnnotationConfiguration instance is required to use <mapping" exception?
body: <p>I'm using Hibernate 4.1.5.SP1, but having trouble configuring a session factory for use with my annotation-based classes.  I try and configure it with</p>
  
  <pre><code>    final Configuration hibConfiguration = new Configuration().configure();       
  
      final ServiceRegistry serviceRegistry = new ServiceRegistryBuilder()
          .applySettings(hibConfiguration.getProperties())
          .buildServiceRegistry();
  
      return hibConfiguration.buildSessionFactory(serviceRegistry);
  </code></pre>
  
  <p>But I get this exception ("An AnnotationConfiguration instance is required to use 
  
  <pre><code>org.quartz.SchedulerException: Job threw an unhandled exception. [See nested exception: javax.ejb.EJBTransactionRolledbackException: An AnnotationConfiguration instance is required to use &lt;mapping class="com.mainco.fdr.myproject.model.UserRole"/&gt;]
      at org.quartz.core.JobRunShell.run(JobRunShell.java:214)
      at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:520)
  * Nested Exception (Underlying Cause) ---------------
  </code></pre>
  
  <p>javax.ejb.EJBTransactionRolledbackException: An AnnotationConfiguration instance is required to use 
          at org.jboss.ejb3.tx.Ejb3TxPolicy.handleInCallerTx(Ejb3TxPolicy.java:87)
          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:249)
          at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.delivery(MessageInflowLocalProxy.java:268)
          at org.jboss.ejb3.mdb.inflow.MessageInflowLocalProxy.invoke(MessageInflowLocalProxy.java:138)
          at $Proxy128.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: org.hibernate.MappingException: An AnnotationConfiguration instance is required to use 
          at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1600)
          at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1555)
          at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1534)
          at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1508)
          at org.hibernate.cfg.Configuration.configure(Configuration.java:1428)
          at org.hibernate.cfg.Configuration.configure(Configuration.java:1414)
          at org.subco.myco.dido.service.AbstractServiceProvider.getSessionFactory(AbstractServiceProvider.java:64)
          at org.subco.myco.dido.service.AbstractServiceProvider.initServices(AbstractServiceProvider.java:127)
          at org.subco.myco.dido.quartz.ProcessOrdersJob.execute(ProcessOrdersJob.java:79)
          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:597)
          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:47)
          at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101)
          at org.jboss.aspects.tx.TxPolicy.invokeInCallerTx(TxPolicy.java:126)
          ... 11 more</p>
  
  <p>Here are my Maven dependencies</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-validator&lt;/artifactId&gt;
          &lt;version&gt;4.3.0.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
          &lt;version&gt;${hibernate.version}&lt;/version&gt;
          &lt;exclusions&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.jboss.spec.javax.transaction&lt;/groupId&gt;
                  &lt;artifactId&gt;jboss-transaction-api_1.1_spec&lt;/artifactId&gt;
              &lt;/exclusion&gt;
              &lt;exclusion&gt;
                  &lt;groupId&gt;org.jboss.logging&lt;/groupId&gt;
                  &lt;artifactId&gt;jboss-logging&lt;/artifactId&gt;
              &lt;/exclusion&gt;
          &lt;/exclusions&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>And here is my hibernate.cfg.xml file …</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt;
  &lt;!DOCTYPE hibernate-configuration PUBLIC
  "-//Hibernate/Hibernate Configuration DTD//EN"
  "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"&gt;
  
  &lt;hibernate-configuration&gt;
      &lt;session-factory&gt;
          &lt;property name="connection.datasource"&gt;MySqlDS&lt;/property&gt;
          &lt;property name="hibernate.connection.pool_size"&gt;10&lt;/property&gt;
          &lt;property name="show_sql"&gt;true&lt;/property&gt;
          &lt;property name="dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/property&gt;
  
          &lt;!-- Enable Hibernate's automatic session context management --&gt;
              &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
          &lt;mapping class="com.mainco.fdr.myproject.model.UserRole" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.Organization" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.Product" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.State" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.Country" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.AccessCode" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.Contract" /&gt;
          &lt;mapping class="com.mainco.fdr.myproject.model.TrainingLink" /&gt; 
      &lt;/session-factory&gt;
  &lt;/hibernate-configuration&gt;
  </code></pre>
  
  <p>I'm replying my application as a JAR file to a JBoss 4.2.2.GA server (don't have control over JBoss version).  What are the proper dependencies I should include and what is the right way to configure my session factory so that I can read annotation-based classes, like the one below …</p>
  
  <pre><code>@Entity
  @Table(name = "lyc_user_role")
  public class UserRole {
  
      @Id
      @Column(name = "USER_ROLE_ID")
      private String roleId;
  </code></pre>