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
Make sure you are importing javax.persistence.Table
and javax.persistence.Column
within your entity classes.
So at the top of each class check for:
import javax.persistence.Table;
import javax.persistence.Column;
This will import the proper JPA annotations into your class.
First thing you have to add data source into your IDE. You can do it in the tab "Database" usually on right side. You can import this data source from your code. You should make sure that you hit button refresh tables. IDEA will load tables and use them for validation. Then you have to inside your JPA facet setup this data source.
There are a few things you need to do. First, configure a Hibernate facet in your Project Structure configuration. You can select your Hibernate configuration file at this point or create a new one. You should then configure your data sources in the Database window (View->Tools Window->Database). Remember to set the database dialect on the Console tab in the database window. Finally, you need to go to the Persistence window (View->Tools Window->Persistence) and add a data source to the appropriate facet. Just right click on the right icon in the tree and select "Add Datasource". The Data Source column has a drop down menu containing all the data sources you have configured. IntelliJ then correctly identifies the tables.
One word of warning. As of v12.04, IntelliJ does not modify your Hibernate configuration file. You still need to map your classes and manually add your database details.
As the path is different depending on your idea version. So from File --> Settings just search for : Unresolved database references. Then do whatever seems ok to you : uncheck the validation or change severity flag.
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
.
I had the data source set correctly, but the column names were not shown. After I changed the schema and the catalog like below, everything was recognized correctly.
@Entity
@Table(name = "stock_detail", schema = "testing", catalog = "")
public class Xyz {
// ...