I have a Spring project for a small web app set up in Intellij IDEA.
It uses JPA on top of Hibernate for the persistence layer. The datasource (MySQL) is defined in Spring application context :
<!-- Values are configured via the property override -->
<bean id="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" >
<property name="driverClassName" value=""/>
<property name="url" value=""/>
<property name="username" value=""/>
<property name="password" value=""/>
</bean>
The actual value are read from a properties file and injected at runtime by Spring using the property-override mechanism.
And then the datasource is injected into the entity manager factory in the same application context:
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="myDataSource"/>
</bean>
Finally the entity manager injected into the DAOs using an annotation:
/**
* Shared, thread-safe proxy for the actual transactional EntityManager
*/
@PersistenceContext
private EntityManager em;
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.
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":
@Entity
@Table(name = "domain")
public class Domain extends AbstractAgendaEntity {
Int this example, it's the "domain"
part that is not considered valid.
I have manually configured my database in the "Database" tool window, I can see my tables and perform SQL queries in the console.
How can I tell Intellij to use this datasource to resolve table names for my JPA entities?
For JPA cannot resolve table/ column. If everything works and you just annoyed by the red error mark, you can change the inspection settings from Error to Warning:-
File --> Settings --> Inspections --> JPA issues --> Unresolved database references in annotations
.