title: Intellij IDEA: specify datasource for JPA validation
body: <p>I have a Spring project for a small web app set up in Intellij IDEA.</p>
  
  <p>It uses JPA on top of Hibernate for the persistence layer. The datasource (MySQL) is defined in Spring application context :</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;!-- Values are configured via the property override --&gt;
      &lt;bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" &gt;
          &lt;property name="driverClassName" value=""/&gt;
          &lt;property name="url" value=""/&gt;
          &lt;property name="username" value=""/&gt;
          &lt;property name="password" value=""/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>The actual value are read from a properties file and injected at runtime by Spring using the property-override mechanism.</p>
  
  <p>And then the datasource is injected into the entity manager factory in the same application context:</p>
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="dataSource" ref="myDataSource"/&gt;
      &lt;/bean&gt;
  </code></pre>
  
  <p>Finally the entity manager injected into the DAOs using an annotation:</p>
  
  <pre><code>/**
   * Shared, thread-safe proxy for the actual transactional EntityManager
   */
  @PersistenceContext
  private EntityManager em;
  </code></pre>
  
  <p>It all works fine when I build and deploy it to Tomcat, but Intellij's JPA validation doesn't seem to understand where to get the datasource from. </p>
  
  <p>In my entities, the tables' names and columns' names are underlined in red and the validation message is "cannot resolve table" or "cannot resolve column":</p>
  
  <pre><code>@Entity
  @Table(name = "domain")
  public class Domain extends AbstractAgendaEntity {
  </code></pre>
  
  <p>Int this example, it's the <code>"domain"</code> part that is not considered valid.</p>
  
  <p>I have manually configured my database in the "Database" tool window, I can see my tables and perform SQL queries in the console.</p>
  
  <p>How can I tell Intellij to use this datasource to resolve table names for my JPA entities?</p>