title: Spring: Missing JPA Metamodel
body: <p>I cannot understand what is going wrong with my simple Spring MVC project with JPA repositories. Could you please give a hint.</p>
  
  <p><strong>Domain</strong>:</p>
  
  <pre><code>package com.test.app;
  
  @Entity
  @Table(name = "foo_table")
  public class FooDomain {
  
      @Id
      @Column(name = "id", unique = true, nullable = false)
      private Integer id;
  
      @Column(name = "text", nullable = false)
      private String text;
  
      // getters &amp; setters here...
  </code></pre>
  
  <p>}</p>
  
  <p><strong>Repository</strong></p>
  
  <pre><code>package com.test.app;
  
  @RepositoryDefinition(domainClass=FooDomain.class, idClass=Long.class)
  public interface FooRepository extends CrudRepository&lt;FooDomain, Long&gt; {}
  </code></pre>
  
  <p><strong>Controller</strong></p>
  
  <pre><code>@Controller
  public class HomeController {
  
      @Autowired
      private FooRepository fooRepository;
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String home(Locale locale, Model model) {
          model.addAttribute("rowsNumber", fooRepository.count());
          return "home";
      }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>root-context.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns &amp; xsi here...&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Defining folders containing bean components (@Component, @Service)  --&gt;
      &lt;context:component-scan base-package="ru.lexikos.app" /&gt;
  
     &lt;import resource="hibernate.xml" /&gt;
  
     &lt;import resource="repositories.xml" /&gt;
  
     &lt;context:component-scan base-package="com.test.app" /&gt;
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>hibernate.xml</strong></p>
  
  <pre><code>&lt;?xml xmlns &amp; xsi here...&gt;
  
      &lt;context:property-placeholder location="classpath:db-connection.properties" /&gt;
  
      &lt;bean id="dataSource" class="org.apache.tomcat.dbcp.dbcp.BasicDataSource"&gt;
          &lt;property name="driverClassName" value="${jdbc.driverClassName}" /&gt;
          &lt;property name="url" value="${jdbc.url}" /&gt;
          &lt;property name="username" value="${jdbc.user}" /&gt;
          &lt;property name="password" value="${jdbc.pass}" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="hibernateProperties"&gt;
              &lt;props&gt;
                  &lt;prop key="hibernate.hbm2ddl.auto"&gt;update&lt;/prop&gt;
                  &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>repositories.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns &amp; xsi here...&gt;
  
    &lt;jpa:repositories base-package="com.test.app"/&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p><strong>Exception</strong></p>
  
  <pre><code>ERROR: org.springframework.web.context.ContextLoader - Context initialization failed
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jpaMapppingContext': Invocation of init method failed; nested exception is ja
  va.lang.IllegalArgumentException: At least one JPA metamodel must be present!
  Caused by: java.lang.IllegalArgumentException: At least one JPA metamodel must be present!
  </code></pre>